[R] Pause in non-interactive mode

Duncan Murdoch murdoch at stats.uwo.ca
Fri Feb 5 10:47:46 CET 2010

On 05/02/2010 4:31 AM, Jonne Zutt wrote:
> Dear all,
> I've found this nice code fragment on the web
> (from Jan T. Kim if I'm correct):
> hitReturn <- function(msg)
> {
> 	invisible(readline(sprintf("%s -- hit return", msg)));
> }
> But it does not seem to work in non-interactive mode
> ( I mean, when I start a script like this: R --vanilla < script.R )
> It simply continues, I guess the stdin is not connected?

stdin is connected to script.R.  That's what the input redirection does.

> Does somebody know how to make it work.

You need to find some other way to communicate with R besides stdin, 
either for your script or for your response to the request to wait. 
It's probably easiest to do the former.  Just start R --vanilla,
then type source("script.R").  Then stdin is still your terminal, and 
the hitReturn function will work.

Duncan Murdoch

> My script plots a few graphs (in X11 windows) and I don't want them to
> disappear immediately.
> A Sys.sleep(infinite) would probably work, but I thought there might
> be a better solution?
> Thanks,
> Jonne.
> ______________________________________________
> 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.

More information about the R-help mailing list