It seems that R copies the whole dataframe when amending one entry in a data frame. I was wondering if there was a way to make R just copy the corresponding data column (e.g. a specific INTSXP below instead of the VECSXP) to maintain copy-on-change policy? Also is there way to do amend-in-place for dataframes?
> x<-data.frame(x=1:1000000,y=1:1000000)
> .Internal(inspect(x))
@62cd2b0 19 VECSXP g0c2 [OBJ,MARK,NAM(2),ATT] (len=2, tl=0)
@f80d0e0 13 INTSXP g0c7 [MARK] (len=1000000, tl=0) 1,2,3,4,5,...
@8ed6970 13 INTSXP g0c7 [] (len=1000000, tl=0) 1,2,3,4,5,...
ATTRIB:
@68f6b40 02 LISTSXP g0c0 []
TAG: @4e58868 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "names" (has value)
@613efd0 16 STRSXP g0c2 [] (len=2, tl=0)
@4e93038 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "x"
@4fe8bd8 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "y"
TAG: @4e62650 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "row.names" (has value)
@113bb328 13 INTSXP g0c1 [] (len=2, tl=0) -2147483648,-1000000
TAG: @4e58d38 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "class" (has value)
@113aa1d8 16 STRSXP g0c1 [MARK,NAM(2)] (len=1, tl=0)
@4ee78a0 09 CHARSXP g1c2 [MARK,gp=0x61] [ASCII] [cached] "data.frame"
> x[1,1]<-3L
> .Internal(inspect(x))
@68eb9f8 19 VECSXP g0c2 [OBJ,NAM(2),ATT] (len=2, tl=0)
@6507290 13 INTSXP g0c7 [] (len=1000000, tl=0) 3,2,3,4,5,...
@7422920 13 INTSXP g0c7 [] (len=1000000, tl=0) 1,2,3,4,5,...
ATTRIB:
@68ef738 02 LISTSXP g0c0 []
TAG: @4e58868 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "names" (has value)
@68ebaa0 16 STRSXP g0c2 [NAM(2)] (len=2, tl=0)
@4e93038 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "x"
@4fe8bd8 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "y"
TAG: @4e62650 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "row.names" (has value)
@f43c418 13 INTSXP g0c1 [] (len=2, tl=0) -2147483648,-1000000
TAG: @4e58d38 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "class" (has value)
@f43c4d8 16 STRSXP g0c1 [NAM(1)] (len=1, tl=0)
@4ee78a0 09 CHARSXP g1c2 [MARK,gp=0x61] [ASCII] [cached] "data.frame"
Thank you!
Shen