[R] Puzzling... puzzling... puzzling...

Duncan Murdoch murdoch.duncan at gmail.com
Mon Feb 13 20:17:01 CET 2012


On 13/02/2012 2:00 PM, Michael wrote:
>   Hi all,
>
> I made sure that it's "env$sRes1$nPositionsOptimizedM" that's correct...
>
> not the "env$sRes1$nPositionsOptimized"...
>
> But it seems both point to the same memory area...

How did you determine that?  The test below just shows that they contain 
the same thing.

> This is very dangerous because I have used naming conventions such as:
>
> MyLongVariableNameForA
>   MyLongVariableNameForB
>   MyLongVariableNameForC
> ...
> ...
>
> Then if internally they are actually the same thing then all my programs
> messed up...
>
> Any thoughts?
>
> >env=new.env()
>
> >load("MyResults.rData", env)
>
> >identical(env$sRes1$nPositionsOptimized, env$sRes1$nPositionsOptimizedM)
>
> [1] TRUE

Changing one of them and seeing the other one change would show that 
they point to the same memory area.  This can happen with environments:  
if you create env1 and set env2 <- env1, then changes to either 
environment will affect the other, because that's how environments 
work.   That's not true of most of the other kinds of objects in R.  
(The exceptions are fairly exotic things that you are unlikely to use.)

Duncan Murdoch



More information about the R-help mailing list