[R] programming advice?

Thomas Lumley tlumley at u.washington.edu
Fri Apr 21 16:57:18 CEST 2006

On Fri, 21 Apr 2006, Charles Annis, P.E. wrote:

> Dear R-helpers:
> I am doing some exploratory programming and am considering a routine that
> has several other routines defined within it, so that I can avoid a large
> and messy global re-programming to avoid naming conflicts.
> My question is this:  Because it is interpreted, does R have to re-build
> these internal routines every time the new routine is called?  I'm not
> overly worried right now about speed, but since my test cases currently run
> for several minutes (which is a long time to me) I don't want to learn a
> lesson the hard way that you, kind readers, might help me avoid.

Yes and no.  The code will be parsed once, but the functions will be 
created each time the routine is called.  This results in some extra 
memory turnover, but is almost certainly not significant in the grand 
scheme of things.

Another approach to avoiding name conflicts is to put your code in a 
package with a namespace and export only the functions you want to be 
visible externally.

You might want to run your code under the profiler (?Rprof) to find out 
where it is really spending all its time.


Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

More information about the R-help mailing list