[Rcpp-devel] How to modifying the elements of a list in the global environment?

Dirk Eddelbuettel edd at debian.org
Fri Oct 19 13:12:26 CEST 2012


On 19 October 2012 at 01:19, Christian Gunning wrote:
| > Anything you pass from R into your C++ routine should be considered
| > read-only. It's typically a bad idea to do in-place updates of the R
| > object you passed in as an argument.
| 
| Really?  I was under the impression that the ability of in-place
| modification was a conscious design decision.

... of .Call() in the R API?

After all, we are passing SEXP -- S Expression POINTERS -- around. So you
always can.

Maybe what Davor was trying to say was along the lines of Doug's "const &"
recommendation for style to avoid surprises.

| Be aware that you've stepped outside of the functional programming
| paradigm, yes.
| But read-only?  From the C++ point of view, it's just memory.

Fullt agreed.
 
| That said, if you want safety (e.g. default R behaviour), use clone().
|  Then you can modify to your heart's content.

Yes, at the cost of creating a copy.

Dirk
-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list