Christian Hoffmann
2004-Mar-04 13:08 UTC
[R] Wait for the user to type <Return>, depending on argument.
Hi, I hope I will not bother you. This is a useful tool in programming pauses: function(ask) { if (ask & interactive() & sink.number()==0) readline("\nType <Return>\t to continue : ") } It guards against batch use and sink-ing: for (ii in 1:5) { cat(ii,"\n") waitReturn(ii %% 2 == 1) } sink("blafile") for (ii in 1:5) { cat(ii,"\n") waitReturn(ii %% 2 == 1) } sink() #look at file "blafile" Documentation: (R style) \name{waitReturn} \alias{waitReturn} \title{Wait for <Return>} \description{ Wait for the user to type <Return>, depending on argument. } \usage{ waitReturn(ask=TRUE) } \arguments{ \item{ask}{ \code{TRUE} will generate the interruption, \code{FALSE} will not.} } \details{ The interruption will only generated for the interactive use of R and if the call is not \code{sink}ed (where it would hang the process). } \value{ None. } \examples{ for (ii in 1:5) { cat(ii,"\n") waitReturn(ii %% 2 == 1) } } \author{Christian W. Hoffmann, \email{christian.hoffmann at wsl.ch}, \url{http://www.wsl.ch/staff/christian.hoffmann} } \keyword{programming} Christian -- -- --> New telephone number, old one will work until 2006 Dr.sc.math.Christian W. Hoffmann, http://www.wsl.ch/staff/christian.hoffmann Mathematics + Statistical Computing e-mail: hoffmacw at wsl.ch Swiss Federal Research Institute WSL Tel: ++41-44-73922.. ..77 (self) CH-8903 Birmensdorf, Switzerland ..11(exchange), ..15 (Fax)