Skip to content
Prev 48598 / 63424 Next

arguments to .Call(), .External should be read-only?

On 08/07/2014 10:05 AM, Greg Minshall wrote:
R doesn't necessarily copy variables on assignment, so code like this:

x <- y <- rnorm(10)

will create *one* vector of length 10, with both x and y referring to 
it.  If your code modifies x the changes will show up in y as well.  
That's the reason for the warning.

See section 5.9.10 for how to handle this safely, but pay attention to 
the last sentence of that section:  any code you write which does this 
is likely to require changes as R's memory management evolves. In 
particular, all of that section is likely to be wrong next spring when R 
3.2.0 is released, as there are changes in the works to implement better 
reference counting.  See <http://developer.r-project.org/Refcnt.html> 
for a discussion.

Duncan Murdoch