[R] How to stop a loop for?

538280 at gmail.com 538280 at gmail.com
Fri Feb 10 17:37:44 CET 2012

If you want to pause for the person to look at a plot before going on
to the next plot then just do:

> par(ask=TRUE)

This will actually allow your loop to continue with calculations while
the user looks at the plot but will pause before drawing the next plot
(hitting enter in the command window or clicking on the plot window
will allow the code to continue).

If you want to pause for something other than a plot then use readline
like Michael suggests.

On Wed, Feb 8, 2012 at 12:45 PM, Juan Andres Hernandez
<jhernandezcabrera at gmail.com> wrote:
> Hi all, I have some time trying to find a way to stop a loop for( ) until the
> user presses the enter key or any other one and the loop can continue.
> This could
> be an example:
>  library(MASS)
>  data <- data.frame(mvrnorm(1000,rep(0,5),Sigma=diag(1,5)))
>  for(i in 1:dim(data)[2]){
>  plot(density(data[,i]), main=paste('histogram',i))
>  #here something like waituntil command
>  }
> Thank's in advance
> Juan A. Hernandez
> Spain.
>        [[alternative HTML version deleted]]
> ______________________________________________
> 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.

Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com

More information about the R-help mailing list