[Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?
Hadley Wickham
h.wickham at gmail.com
Fri Jul 26 17:44:09 CEST 2013
> // note: The FUN will change the object x itself
> // hence - it must be clear to use an object we wish to change
> (it will NOT be copied!)
Why do you want to do that? It's a generally a bad idea to modify R
objects in place.
Here's a simple example showing why C level modification of R object
is particularly dangerous:
library(inline)
foo <- cfunction(c(x = "SEXP"), '{
INTEGER(x)[0] = 0;
return R_NilValue;
}')
x <- 1:10
y <- x
foo(x)
# First value is modified as expected
x
# But y is also modified!
y
Hadley
--
Chief Scientist, RStudio
http://had.co.nz/
More information about the Rcpp-devel
mailing list