Hello all,

Still taking my first steps, I've come across a feature (?) I cannot yet
make sense of. Consider a simple function with its argument passed by value:

SEXP fun(SEXP arg)
{
using namespace Rcpp;

NumericVector vec(arg);
for(int i=0; i<vec.size(); i++)
vec[i] += 1;

return vec;
}

The call in R is declared as

R.fun <- function(arg)
{
.Call( "fun", as.double(arg), PACKAGE = "wonderland" )
}


Using Rcpp 0.8.6 and R-2.11.1, I get

> arg <- 1:2 # or any vector of size > 1
> result <- R.fun(arg)
> result; arg
[1] 2 3
[1] 1 2

That's fine -- but if I take as argument a vector of size 1, I get

> arg <- 1
> result <- R.fun(arg)
> result; arg
[1] 2
[1] 2

What am I missing?
Thanks, Jo
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to