On Wed, 21 Jun 2000, Gardar Johannesson wrote:
>
>
> I have this 'odd' problem; I need to let R pause, for a given time,
before
> starting next iteration in a loop. I'm using the following to do this
> task, but feel a little bit guilty because I'm using as much CPU time
as I
> can get while pausing:
>
> while(keepGoing) {
> t.end <- proc.time()[3] + 5 ## the time this loop should end at
>
> [block of R commands]
>
> while(proc.time()[3] < t.end) {}
> }
>
> This guaranty, at least, 5 second evaluation time for each loop in the
> above case.
>
> Can I delay the loop more efficiently, that is, not using as much CPU time
> as in the above case?
Try
system("sleep 5")
That will use essentially no CPU time, but it will block the process.
That stops re-sizing graphics windows for examples, but on Unix
is not too serious. I am not sure of the effect on the GNOME console,
nor what happens if tcltk is running.
If anyone wants to do this on Windows. take a look at the xgobi
function in the current version of the XGobi package, as that package
has an equivalent in C (that does handle events during the pause).
We do plan to have a version of this for all platforms in due course.
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._