[R] Reference classes and memory consumption

Jan Mueller Jan.Mueller at ipsos.com
Tue Jun 19 11:22:21 CEST 2012


Dear All,

It seems that reference classes consume a lot of memory which became a problem for my rather extensive simulation. 
I prepared a small example. An instance of this minimal class uses about 20K on disk. 

rm(list=ls(all=TRUE));

MySmallClass = setRefClass("MySmallClass", 
     fields = list(
		myField = "numeric"
     ),
     methods = list(
	   initialize = function(f) {
	     myField <<- f;
         })	   
);

o = MySmallClass$new(10);
saveRDS(o, file="C:\\o.rds");
file.info("C:\\o.rds")$size;


Result:
[1] 21274

My questions:
Is saveRDS() is representative for memory usage?
If so, is there a way to shrink these objects to a smaller size?

I use R 2.15.0 on a 32 Bit Windows 7 system.

Best regards,
Jan



More information about the R-help mailing list