I am curious to know if the behavior of data.tablea with respect to environments is inconsistent. When working with data.tables, the expectation is that assigning a new variable to a data.table does not copy data but makes a new pointer to the existing table. This does not appear to be true true when the source data.table exists in another environment. For 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 we try and assign a new name to mydata
, we don't get the expected behavior of having a pointer to the same data.
mydata2 <- mydata # also makes a _copy_
mydata2[['y']] <- 5 # change the data
identical( mydata2, mydata )
> FALSE
mydata2
does not point to (the same value) as mydata
. It has made a copy. This is not what I would have expected from data.table. I expect data.tables to behave more as singletons in which only one copy of the data exists unless an explicit copy
is made.
In addition, $<-
and [[<-
cause copies to be made on the global environment. $<<-
and [[<<-
do not (as expected). Also, :=
does not cause a copy to be made.
Is this inconsistent with respect to data.table's intent?
Is this behavior inconsistent with 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 Good Sport