[R] execution of source() command

Rainer M Krug rkrug at sun.ac.za
Fri Sep 15 12:10:50 CEST 2006


Prof Brian Ripley wrote:
> On Fri, 15 Sep 2006, Rainer M Krug wrote:
> 
>> Hi
>> I have two questions concerning the source("test.R") command.
>> 1) Is there any command which I can put into the test.R script file
>> which aborts the execution of the script? At the moment I use
>>
>> CodeToBeExecutedInScript
>> if (FALSE)
>> {
>>     CodeNotToBeExecutedInScript
>> }
>>
>> which is not elegant, but it works. I would prefer something like:
>>
>> CodeToBeExecutedInScript
>> CommandToAbotrExecutionOfScriptFile
>> CodeNotToBeExecutedInScript
> 
> ?stop or ?q, depending on what you mean by 'aborts the execution'.

Thanks - I would have expected to find it together with the other
flowcontrol commands like if, while, ...

> 
>> 2) When I call source("test.R") and it is running for some time. Does
>> changing the file test.R while it is executed change the execution, i.e.
>> does the call of source() load the script file into memory and parses
>> and executes it from there or does it parse and execute the file on
>> the disk.
> 
> The help file says:
> 
>      'source' causes R to accept its input from the named file or URL
>      (the name must be quoted) or connection.  Input is read and
>      'parse'd by from that file until the end of the file is reached,
>      then the parsed expressions are evaluated sequentially in the
>      chosen environment.
> 
> library(fortunes); fortune("WTFM")
> 
> 

Again - thanks a lot for the clarification

Rainer
-- 
Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Department of Conservation Ecology and Entomology
University of Stellenbosch
Matieland 7602
South Africa

Tel:		+27 - (0)72 808 2975 (w)
Fax:		+27 - (0)21 808 3304
Cell:		+27 - (0)83 9479 042

email:	RKrug at sun.ac.za
      	Rainer at krugs.de



More information about the R-help mailing list