I have a cppFunction
with a vector ints
as input, e.g:
library(Rcpp)
cppFunction('double test2(NumericVector ints) {
return 42;
}')
The output is correct if passing a vector of length at least 1:
> test2(1)
[1] 42
> test2(1:10)
[1] 42
For input of length 0 however I get:
> test2(c())
Error: not compatible with requested type
Is there any way to pass a vector of length 0 or larger to my function? I.e. my expected output is:
> test2_expectedoutput(c())
[1] 42
I know I could control for this in R by checking in R first and calling a different version of the function but would like to avoid this. I expect there is some easy solution out there since within cpp I could also have a NumericVector
of length 0 if I understand correctly what NumericVector zero;
does. The only related question I could find was this on how to return a NULL object from within a Rcpp function to R.