From wdunlap at tibco.com  Tue Feb 26 17:47:18 2013
From: wdunlap at tibco.com (William Dunlap)
Date: Tue, 26 Feb 2013 16:47:18 +0000
Subject: [Rd] Running R scripts with interactive-style evaluation
In-Reply-To: <68D9049B548E6342A7FA7EC383707BA3F6EB7348EC@w2008srv.haus.local>
References: <68D9049B548E6342A7FA7EC383707BA3F6EB7348EC@w2008srv.haus.local>
Message-ID: <E66794E69CFDE04D9A70842786030B931B909E15@PA-MBX04.na.tibco.com>

Which part of the read-eval-print loop loop ("REPL loop") do you need?

source(file, print=TRUE) gives you the printing part, which is what I usually want.

Opening a file connection and repeatedly calling parse(n=1) gives you the read part,
  > tf <- tempfile()
  > cat(file=tf, sep="\n", "x <- 1 +", "10 ; y <- 2:7", "10:3")
  > f <- file(tf, open="rt")
  > parse(f, n=1)
  expression(x <- 1 + 10)
  > parse(f, n=1)
  expression(y <- 2:7)
  > parse(f, n=1)
  expression(10:3)
  > parse(f, n=1)
  expression()
  > close(f)
and you can copy the code from source() to get the eval and print stuff right.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf
> Of Marc Aurel Kiefer
> Sent: Tuesday, February 26, 2013 2:08 AM
> To: r-devel at r-project.org
> Subject: [Rd] Running R scripts with interactive-style evaluation
> 
> 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.
> 
> 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.
> 
> It doesn't matter if it's a source()-like way or "R CMD BATCH" or even feeding stdin to R
> or whatever...
> 
> Regards,
> 
> Marc
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Running R scripts with interactive-style evaluation
William Dunlap