[R] Scripting with an external editor

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Mar 24 11:26:38 CET 2003

On Mon, 24 Mar 2003, Jim Lemon wrote:

> I've had time to return to the "external editor" project. The following 
> function does almost what I want, which is to allow an external editor to 
> feed command lines to R.
> ext.editor<-function(editor) {
>  ext.input<-pipe(editor,"r")
>  eval(parse(ext.input))
>  close(ext.input)
> }
> While the description of parse() indicates that it should parse input line by 
> line, the output of the editor is not read until it exits. The external 
> editor is sending the output as requested, so I must be using the wrong 
> connection setup. Any hints?

?parse says

     `parse' returns the parsed but unevaluated expressions in a list. 
     Each element of the list is of mode `expression'.

that is, it takes all the input and returns a list once all the input has 
been parsed.  There is no multi-tasking in the R evaluator, and you have 
no loop in your code, so eval can only be called once when parse exits.

I am not clear what you actually want.  If it is to repeatedly send a
block of code to R and get that block evaluated then you need to indicate
the end of the block somehow, split the pipe stream up into blocks and run
a loop to parse and evaluate each block.  If you want to simulate the
command-line, the easiest way to do this is to submit to the command line,
and to help with that you would have to at least tell us your platform!

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