I have cppFunctionwith a vector intsas input, for example:
library(Rcpp)
cppFunction('double test2(NumericVector ints) {
return 42;
}')
The result is correct if you skip a vector of at least 1 length:
> test2(1)
[1] 42
> test2(1:10)
[1] 42
To enter a length of 0, however, I get:
> test2(c())
Error: not compatible with requested type
Is there a way to pass a vector of length 0 or more to my function? That is my expected result:
> test2_expectedoutput(c())
[1] 42
I know that I can control this in R by first checking R and calling another version of the function, but would like to avoid this. I expect that there will be some simple solution, since inside cpp I could also have a NumericVectorlength of 0 if I understood correctly what it was doing NumericVector zero;. The only related question that I could find was how on how to return NULL object from Rcpp functions in the R .