From murdoch.duncan at gmail.com  Tue Feb 26 14:06:08 2013
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Tue, 26 Feb 2013 08:06:08 -0500
Subject: [Rd] Running R scripts with interactive-style evaluation
In-Reply-To: <68D9049B548E6342A7FA7EC383707BA3F6EB7348EC@w2008srv.haus.local>
References: <68D9049B548E6342A7FA7EC383707BA3F6EB7348EC@w2008srv.haus.local>
Message-ID: <512CB340.7020101@gmail.com>

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



[Rd] Running R scripts with interactive-style evaluation
Duncan Murdoch