[R] Sourcing commands but delaying their execution

Liaw, Andy andy_liaw at merck.com
Fri Aug 3 21:01:38 CEST 2007


Here's one possibility:

The file "garbage.R" has

  x <- rnorm(100)
  print(summary(x))

You can do:

  cmds <- parse(file="garbage.R", n=NA)

and when you want to execute those commands, do

  eval(cmds)

Andy 

From: Dennis Fisher
> 
> 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.
> 
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}



More information about the R-help mailing list