[Rd] arguments to .Call(), .External should be read-only?
Dirk Eddelbuettel
edd at debian.org
Tue Jul 8 17:18:54 CEST 2014
It's one of my favourite Rcpp puzzles:
R> cppFunction('bool foo(NumericVector x) { x = 2 * x; return(true); }')
R> x <- 1:4 # note that x is now an int vector
R> foo(x) # so this casts to numeric --> copy
[1] TRUE
R> x
[1] 1 2 3 4 # still the same
R> x <- 1:4 * 1.0 # BUT now we create a numeric vector
R> foo(x)
[1] TRUE
R> x # and that one DOES get modified
[1] 2 4 6 8
R>
Morale: The P in SEXP means that you get to change the external object. So
as Duncan and the WRE manual say: proceed with some caution.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the R-devel
mailing list