I am trying to write a C++/Rcpp function that has an optional argument whos default needs to be a vector of length 1 with a value of 0. The following does not compile properly:
cppFunction("std::vector<int> test(std::vector<int> out = {0}) {
  return out;
}")
I get the following error:
Error in cppFunction("std::vector test(std::vector out = {1}) {\n return out;\n}") : No function definition found In addition: Warning messages: 1: No function found for Rcpp::export attribute at fileee5f629605d7.cpp:5 2: In sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, : No Rcpp::export attributes or RCPP_MODULE declarations found in source
What is the right way to do this?
This answer was posted on the Rcpp issue tracker. This is the desired result that I wanted just not with std::vector.
cppFunction("IntegerVector test(IntegerVector out = IntegerVector::create(0)) {
   return out;
}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With