[R] Sourcing commands but delaying their execution

Gabor Grothendieck ggrothendieck at gmail.com
Fri Aug 3 19:34:41 CEST 2007


Merged file can become:

... current file1 contents ...
f <- function() {
... current file 2 contents ...
}

and then source that followed by running your middle code
followed by running f().

Of course, you may need to make some changes in the body
of f due to the changed scoping that this introduces.

On 8/3/07, Dennis Fisher <fisher at plessthan.com> wrote:
> Colleagues:
>
> I have encountered the following situation:
>        SERIES OF COMMANDS
>        source("File1")
>        MORE COMMANDS
>        source("File2")
>
> Optimally, I would like File1 and File2 to be merged into a single
> file (FileMerged).  However, if I wrote the following:
>        SERIES OF COMMANDS
>        source("FileMerged")
>        MORE COMMANDS
>
> I encounter an error: the File2 portion of FileMerged contains
> commands that cannot be executed properly until "MORE COMMANDS" are
> executed.  Similarly, sourcing FileMerged after MORE COMMANDS does
> not work because MORE COMMANDS requires the information from the
> File1 portion of FileMerged.
>
> I am looking for a means to source FileMerged but not execute some of
> the commands immediately.  Functionally this would look like:
>        SERIES OF COMMANDS
>        source("FileMerged")    # but withhold execution of some of the commands
>        MORE COMMANDS
>        COMMAND TO EXECUTE THE WITHHELD COMMANDS
>
> Does R offer some option to accomplish this?
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list