[R] Lengthy delay in sourcing a large function

From: Dennis Fisher <fisher_at_plessthan.com>
Date: Mon, 02 Jun 2008 14:28:25 -0700


I have a script that contains ~ 10,000 lines of code. Most of it is written as small functions. However, for various reasons, the final function is ~1500 lines of code. I realize that this may not be optimal but the code evolved that way and breaking it into smaller pieces is complicated because of the passing of arguments. I have "cat(date())" statements at various places in the code so that I can track the actions as the script is executed.

I am running version 2.7.0 on a quad processor Mac and I call the script from the OS: R --slave < Script.R

It takes ~ 5 seconds for R to read the first 8000 lines of code (as indicated by the time difference between the first record of the file and the date issued immediately before the large function). Then, reading the large function (1500 lines) takes ~ 1 minute. I have improved the delay by moving some of the code from the large function.

I don't understand why the second portion of the code is read so much slower than the first. In that the code is a function, I presume that nothing within the function is executed until the function is called.

Does anyone have any experience with this issue?


Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220

        [[alternative HTML version deleted]]

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. Received on Mon 02 Jun 2008 - 22:27:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 23:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive