You have not told us your version of R. In earlier versions of R readline() reads a line from the script (and input buffering affects which line: a number of packages fail their example checks on some platforms because of this). In R-devel it returns "" immediately.

To make this work you need to use Rscript, which distinguishes stdin() and "stdin". Try out

% Rscript foo.R

where  foo.R is

message("a")
invisible(readLines("stdin", n=1))
message("b")

and see ?stdin and ?file for why it works.

On Fri, 5 Feb 2010, 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?

Does somebody know how to make it work.

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.

--
Brian D. Ripley,                  rip...@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

______________________________________________
R-help@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.

Reply via email to