[Rcpp-devel] Passing arguments by value: unexpected behaviour
Johannes Egner
johannes.egner at gmail.com
Tue Sep 14 11:29:37 CEST 2010
Romain,
many thanks for the (incredibly speedy) reply.
You are missing that :
>
> > typeof( 1:2 )
> [1] "integer"
>
> So as.double creates a new numeric vector, but:
>
> > typeof( 1 )
> [1] "double"
>
> So as.double just returns its input. as.double is a primitive function in
> R, so it does not really have pass by value semantics.
>
Ok, I %really% should have picked up on that -- my R knowledge usually does
stretch this far.
> By design, when you create an Rcpp object, you don't get a copy of the
> original object, you point to the same SEXP.
Yup, I know that from the documentation.
> If you want a copy, you can use clone, as in :
>
> NumericVector vec = clone<NumericVector>(arg)
>
This is a very interesting function (templated, I suppose) -- I haven't seen
this in the examples/presentations. Thanks.
Incidentally, I have seen you now have a cheat sheet (or quick reference, as
it's called on CRAN). I think this is very good idea for a certain group of
users (like me -- those that want to get results relatively quickly without
getting into %all% the nitty-gritty details), and it is worth keeping up to
date. Clone as above for instance seems like a good candidate to add. Maybe
the tex-source can even be put on some website (for personal
additions/alterations)?
Best, Jo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20100914/a7931c51/attachment.htm>
More information about the Rcpp-devel
mailing list