r - <-, [[<-, $<- and := with environments -


i curious know if behavior of data.tablea respect environments inconsistent. when working data.tables, expectation assigning new variable data.table not copy data makes new pointer existing table. not appear true true when source data.table exists in environment. example,

> attach( new.env(), name="dt" ) > e <- as.environment("dt") >  > assign( "mydata", data.table( x=1:3, y=1 ), e) > mydata    x y 1: 1 1 2: 2 1 3: 3 1 > ls() [1] "e"        

if try , assign new name mydata, don't expected behavior of having pointer same data.

mydata2 <- mydata     # makes _copy_ mydata2[['y']] <- 5   # change data identical( mydata2, mydata )   > false 

mydata2 not point (the same value) mydata. has made copy. not have expected data.table. expect data.tables behave more singletons in 1 copy of data exists unless explicit copy made.

in addition, $<- , [[<- cause copies made on global environment. $<<- , [[<<- not (as expected). also, := not cause copy made.

is inconsistent respect data.table's intent?

is behavior inconsistent data.table?

r version information:

r.version _
platform x86_64-unknown-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 0.1
year 2013
month 05
day 16
svn rev 62743
language r
version.string r version 3.0.1 (2013-05-16) nickname sport

the operators <- , = not copy in r objects:

a = c(1:10) .internal(inspect(a)) #@0x000000001072aa28 13 intsxp g0c4 [nam(1)] (len=10, tl=0) 1,2,3,4,5,... b = .internal(inspect(b)) #@0x000000001072aa28 13 intsxp g0c4 [nam(2)] (len=10, tl=0) 1,2,3,4,5,... 

and neither mydata copied when mydata2 <- mydata (you can check again using above method, or trying smth mydata[, y := 5] right after assignment , seeing how changes both tables).

on other hand [[<- , plethora of other assignment operators copy both data.frame , data.table (and that's see) , way modify data.table reference use :=. none of environment stuff above matters.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -