Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function param default value std:vector initialization with Rcpp and C++11?

Tags:

r

c++11

rcpp

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?

like image 599
Ryan Hope Avatar asked Oct 29 '25 09:10

Ryan Hope


1 Answers

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;
}")
like image 186
Ryan Hope Avatar answered Oct 31 '25 01:10

Ryan Hope



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!