[R] does R read commands from scripts instantanously or seuqently during processing

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Mar 15 13:14:29 CET 2013


On 15/03/2013 10:40, Jannis wrote:
> Dear all,
>
> thanks, Rolf and Jeff, for your replies. The command below runs under
> Suse Linux. I guess, hoewever, the phenomena I observed would heappen
> under other oprating systems as well. The reason why I asked was that R
> produced some error messages that did not really point me to the
> direction of the edited script file. These errors were usually something
> like:
>
> Error: unexpected symbol in "cess finished."
>
> The line in the script which caused this error is:
>
> print(paste(as.character(Sys.time()), ': Process finished.', sep=''))
>
> This line contains valid R code and would normally not produce an error.
> Some testing showed that the error above only happens when I edit the
> code of the script while the script is run. So R probably reads in a
> script submitted that way seuqently directly while executing the

If reading from stdin, it does (like any other interpreter): however 
stdin is buffered if re-directed, so the input script is read in blocks 
from a file (the size of the block depending on the OS).

> individual commands. No idea though what happens if i would start the
> script via source inside R itself.

R is Open Source, and you can read the code of source().  It really 
isn't hard to see that it parses the whole file, then executes the 
parsed expressions one at a time.

>
>
> Thanks again for your suggestions
> Jannis
>
>
> On 14.03.2013 22:47, Rolf Turner wrote:
>> On 03/15/2013 05:13 AM, Jannis wrote:
>>> Dear R community,
>>>
>>>
>>> when I source a script into R via:
>>>
>>>
>>> R --slave < scriptname.R
>>>
>>>
>>> is the whole script file read at once during startup or is each
>>> indivdual line of code read seqnetially during the execution (i.e.
>>> directly before r processes the respective command)? In other words,
>>> can I savely edit the  scriptname.R file even when an active R process
>>> still runs the command above?
>>
>>
>> Experiment.  Build a toy script with a loop that never terminates. Set
>> it going.  Edit the script and change the code so that the loop
>> terminates.
>> See what happens.
>>
>> [It seems to me that nothing happens, so that you *can* "safely" edit
>> the script while
>> the process runs.  But further experimentation would be advisable.]
>>
>>      cheers,
>>
>>          Rolf Turner
>
> ______________________________________________
> 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.


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