[Rd] Running R scripts with interactive-style evaluation
Duncan Murdoch
murdoch.duncan at gmail.com
Tue Feb 26 14:06:08 CET 2013
On 13-02-26 5:07 AM, Marc Aurel Kiefer wrote:
> Hi,
>
> when running a R-script like this:
>
> enable_magic()
> compute_stuff()
> disable_magic()
>
> the whole script is parsed into a single expression and then evaluated, whereas when using the interactive shell after each line entered, a REPL loop happens.
It's actually a vector of expressions that are evaluated one at a time,
but close enough...
> Is there a way to make a script evaluation behave like this, because I need a single REPL iteration for every expression in the script.
You don't say why you need that. From your subject line, I'm guessing
you want to do something like a user prompt, then wait for user input,
then another user prompt, etc.? So the fact that disable_magic() was
parsed at the beginning shouldn't matter. Or does it?
>
> It doesn't matter if it's a source()-like way or "R CMD BATCH" or even feeding stdin to R or whatever...
I think it all depends on what kind of input users are allowed to type,
but basically this is something you'll need to write yourself, I don't
think any of the normal running modes of R will suit you. Take a look
at the source to source() or to the Sweave-related functions for ideas.
Duncan Murdoch
More information about the R-devel
mailing list