Hi there,
I know this question may sounds strange, but here it goes:
Is it possible to delay the speed of a for loop? For example, if I
have:
for (i in 1:100) {
blah blah blah
}
within the for loop I want to draw a series of plots, and combining the
plots together I'll have an animation. Problem is the loop is too fast
and I only see the end result (which is not surprising actually).
What I want is to slow down the loop (if possible), and so I have time
to save each "part" of the loop (or each plot when it is produced) as
a
gif file, and later on put these gif files together using some kind of
GIF Animators.
Anyway, just wonder if the for loop can be slowed down forcebly.
Cheers,
Ko-Kang (Kevin) Wang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Ko-Kang.vcf
Type: text/x-vcard
Size: 306 bytes
Desc: Card for Ko-Kang Wang
Url :
https://stat.ethz.ch/pipermail/r-help/attachments/20000731/d73ba8d7/Ko-Kang.vcf
> Date: Mon, 31 Jul 2000 23:56:34 +1200 > From: Ko-Kang Wang <Ko-Kang at xtra.co.nz> > X-Accept-Language: en,zh-TW,zh-CN,zh,en-GB,en-US > To: R Help <r-help at stat.math.ethz.ch> > Subject: [R] Loop Delaying > > Hi there, > > I know this question may sounds strange, but here it goes: > > Is it possible to delay the speed of a for loop? For example, if I > have: > > for (i in 1:100) { > blah blah blah > } > > within the for loop I want to draw a series of plots, and combining the > plots together I'll have an animation. Problem is the loop is too fast > and I only see the end result (which is not surprising actually). > > What I want is to slow down the loop (if possible), and so I have time > to save each "part" of the loop (or each plot when it is produced) as a > gif file, and later on put these gif files together using some kind of > GIF Animators.You can save the plot from R code within the loop, e.g. by savePlot on Windows. I suspect that is what you really want. I suggest you don't mention GIF in connection with a GNU project, as some people are very against them.> Anyway, just wonder if the for loop can be slowed down forcebly.Not easily yet, but 1.2.0 will have a Sys.sleep function to do so. On Windows you can `borrow' this by using library(xgobi) and looking at the .C call at the end of the xgobi function. -- Brian D. Ripley, ripley at 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 31 Jul 2000, Ko-Kang Wang wrote:> Hi there, > > I know this question may sounds strange, but here it goes: > > Is it possible to delay the speed of a for loop? For example, if I > have: > > for (i in 1:100) { > blah blah blah > }Several days before was a similar question, I don't know the answers but i would guess that slowing might be one possibility (done by a additional inside loop that does nothing) for( i in ...){ .... for(j in 1:100000)rnorm(100) ... } but.:> within the for loop I want to draw a series of plots, and combining the > plots together I'll have an animation. Problem is the loop is too fast > and I only see the end result (which is not surprising actually).a better way might be -perhaps- to set par(ask=T)> What I want is to slow down the loop (if possible), and so I have time > to save each "part" of the loop (or each plot when it is produced) as a > gif file, and later on put these gif files together using some kind of > GIF Animators....or you automatically save the plots dev.print(postscript,file=paste("foo",i,sep="") ) ...look on them later... or you use the possibilty to make several pages> postscript(file="/tmp/temp.ps") > plot(0,0) > plot(0,0) > plot(0,0) > dev.off()1 P. ** To YOU I'm an atheist; to God, I'm the Loyal Opposition. Woody Allen ** P.Malewski Tel.: 0531 500965 Maschplatz 8 Email: P.Malewski at tu-bs.de ************************38114 Braunschweig******************************** -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
A few possibilities:
1. if you're on a Unix system you can say something like
system("sleep 5") to delay for 5 seconds.
2. you can set par(ask=TRUE) to have R pause and ask you to hit ENTER
between each new plot.
3. you can do a classic "delay loop" (for i in 1:10^6 {}) inside the
for
loop.
4. rather than pausing and (I guess) manually saving each plot to a
file, why not write them out to separate files using dev2bitmap() or png()
(or something) within the loop? (e.g.
png(paste("outgraph.",i,sep="")) )
?
On Mon, 31 Jul 2000, Ko-Kang Wang wrote:
> Hi there,
>
> I know this question may sounds strange, but here it goes:
>
> Is it possible to delay the speed of a for loop? For example, if I
> have:
>
> for (i in 1:100) {
> blah blah blah
> }
>
> within the for loop I want to draw a series of plots, and combining the
> plots together I'll have an animation. Problem is the loop is too fast
> and I only see the end result (which is not surprising actually).
>
> What I want is to slow down the loop (if possible), and so I have time
> to save each "part" of the loop (or each plot when it is
produced) as a
> gif file, and later on put these gif files together using some kind of
> GIF Animators.
>
> Anyway, just wonder if the for loop can be slowed down forcebly.
>
> Cheers,
>
> Ko-Kang (Kevin) Wang
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi,
How about inserting a while loop in your for loop that would do nothing
until a preset amount of time as past.
Something like:
wait <- function(wait.time = 5){
now <- proc.time()[3]
while(proc.time()[3] < (now + wait.time)) dum <- 0
}
Regards
YG
----- Original Message -----
From: "Ko-Kang Wang" <Ko-Kang at xtra.co.nz>
To: "R Help" <r-help at stat.math.ethz.ch>
Sent: Monday, July 31, 2000 7:56 AM
Subject: [R] Loop Delaying
> Hi there,
>
> I know this question may sounds strange, but here it goes:
>
> Is it possible to delay the speed of a for loop? For example, if I
> have:
>
> for (i in 1:100) {
> blah blah blah
> }
>
> within the for loop I want to draw a series of plots, and combining the
> plots together I'll have an animation. Problem is the loop is too fast
> and I only see the end result (which is not surprising actually).
>
> What I want is to slow down the loop (if possible), and so I have time
> to save each "part" of the loop (or each plot when it is
produced) as a
> gif file, and later on put these gif files together using some kind of
> GIF Animators.
>
> Anyway, just wonder if the for loop can be slowed down forcebly.
>
> Cheers,
>
> Ko-Kang (Kevin) Wang
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._