Hi, Is there a way to pass the address of a data.frame through a set of functions in R? I've got some code which is slowing down I think because my data.frames are getting much larger - now approaching 1 million rows by 50-100 columns - and my functions - originally written for much smaller data elements are sampling these data.frames a couple of layers down. Before I rewrite them to do the sampling at the top level if there was a way to pass the address of the data.frame instead of the a copy of the whole thing then I suspect that would speed things up significantly. Thanks, Mark
Gabor Grothendieck
2009-Sep-18 23:45 UTC
[R] Any concept of 'by reference' or 'address of' in R?
You can use R environments or proto objects from the proto package (http://r-proto.googlecode.com) which are environments with additional oo support using the prototype model) or the oo.R package which is similar but uses a more conventional oo model. On Fri, Sep 18, 2009 at 7:38 PM, Mark Knecht <markknecht at gmail.com> wrote:> Hi, > ? Is there a way to pass the address of a data.frame through a set of > functions in R? I've got some code which is slowing down I think > because my data.frames are getting much larger - now approaching 1 > million rows by 50-100 columns - and my functions - originally written > for much smaller data elements are sampling these data.frames a couple > of layers down. > > ? Before I rewrite them to do the sampling at the top level if there > was a way to pass the address of the data.frame instead of the a copy > of the whole thing then I suspect that would speed things up > significantly. > > Thanks, > Mark > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
David Winsemius
2009-Sep-18 23:48 UTC
[R] Any concept of 'by reference' or 'address of' in R?
On Sep 18, 2009, at 7:38 PM, Mark Knecht wrote:> Hi, > Is there a way to pass the address of a data.frame through a set of > functions in R? I've got some code which is slowing down I think > because my data.frames are getting much larger - now approaching 1 > million rows by 50-100 columns - and my functions - originally written > for much smaller data elements are sampling these data.frames a couple > of layers down. > > Before I rewrite them to do the sampling at the top level if there > was a way to pass the address of the data.frame instead of the a copy > of the whole thing then I suspect that would speed things up > significantly. >You could pass <it>'s name as a string and then when it arrived at the destination, ... get() it: ?get -- David Winsemius, MD Heritage Laboratories West Hartford, CT
Don MacQueen
2009-Sep-19 00:11 UTC
[R] Any concept of 'by reference' or 'address of' in R?
I wouldn't assume R is making a copy; it depends on what you're doing with the dataframe. I'd suggest using Rprof to find out where the cpu time is being spent. If you can adapt your problem to use all numbers or all characters then you can store the data in a matrix instead of a data frame, and potentially speed things up. (That advice is based on my own experience from a fairly large number of years ago, so it's possible that developments in R since then could negate the advice.) -Don At 4:38 PM -0700 9/18/09, Mark Knecht wrote:>Hi, > Is there a way to pass the address of a data.frame through a set of >functions in R? I've got some code which is slowing down I think >because my data.frames are getting much larger - now approaching 1 >million rows by 50-100 columns - and my functions - originally written >for much smaller data elements are sampling these data.frames a couple >of layers down. > > Before I rewrite them to do the sampling at the top level if there >was a way to pass the address of the data.frame instead of the a copy >of the whole thing then I suspect that would speed things up >significantly. > >Thanks, >Mark > >______________________________________________ >R-help at r-project.org mailing list >https://*stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062
Steve Lianoglou
2009-Sep-19 01:10 UTC
[R] Any concept of 'by reference' or 'address of' in R?
On Fri, Sep 18, 2009 at 8:11 PM, Don MacQueen <macq at llnl.gov> wrote:> I wouldn't assume R is making a copy; it depends on what you're doing with > the dataframe.Indeed ... I thought R had copy-on-write semantics for function arguments, no? If so, then if your function doesn't change the elements in the matrix/data.frame, then you shouldn't have to worry, and look to optimize elsewhere ... -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact