[R] execution of source() command

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Sep 15 11:03:29 CEST 2006


On Fri, 15 Sep 2006, Rainer M Krug wrote:

> Hi
>
> Linux SuSE 10
>
> platform       i686-pc-linux-gnu
> arch           i686
> os             linux-gnu
> system         i686, linux-gnu
> status
> major          2
> minor          3.1
> year           2006
> month          06
> day            01
> svn rev        38247
> language       R
> version.string Version 2.3.1 (2006-06-01)
>
> 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'.

> 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")


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list