Paul Johnson
2012-Jun-03 18:00 UTC
[R] memory usage benefit from "anonymous" variable constructions.
This is an "I was just wondering" question. When the package "dataframe" was announced, the author claimed to reduce the number of times a data frame was copied, I started to wonder if I should care about this in my projects. Has anybody written a general guide for how to write R code that doesn't needlessly exhaust RAM? In Objective-C, we used to gain some considerable advantages by avoiding declaring objects separately, using anonymous variable instead. The storage was allocated on the stack, I think, and I think there was talk that the numbers might stay 'closer' to the CPU (register?) for immediate usage. Does this benefit in R as well? For example, instead of the way I would usually do this: mf <- model.frame(model) y <- model.response(mf) Here is the anonymous alternative, mf is never declared y <- model.response(model.frame(model)) On the face of it, I can imagine this might be better because no permanent thing "mf" is created, the garbage collector wouldn't be called into play if all the data is local and disappears immediately. But, then again, R is doing lots of stuff "under the hood" that I've never bothered to learn about. pj -- Paul E. Johnson Professor, Political Science ? ?Assoc. Director 1541 Lilac Lane, Room 504 ? ? Center for Research Methods University of Kansas ? ? ? ? ? ? ? University of Kansas http://pj.freefaculty.org ? ? ? ? ? ?http://quant.ku.edu
Reasonably Related Threads
- example to demonstrate benefits of poly in regression?
- portableParalleSeeds Package violation, CRAN exception?
- Working on a Vignette called Rcheology
- Windows Task Scheduler and R updates. Need basic tips
- shade overlapping portions of circles (or other shapes)