[R] Way to make R idle for some time and try something again later

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Jul 30 07:44:13 CEST 2005

This depends on what else is going on.  My guess is that you are running 
the Aqua GUI, and it is servicing the GUI which is taking the time, not R 

On all of Linux, Solaris and Windows (RGui or Rterm) Sys.sleep() does use 
very close to zero resources at the beginning of a session, but things may 
be different if e.g. tcltk widgets are in use.

On Fri, 29 Jul 2005, Don MacQueen wrote:

> I done something very similar -- have R watch a file, and whenever
> new data is added to the file, read the new data from the file. In my
> case, new data was arriving once per minute, so I needed to have R
> wait about a minute before looking for new data.
> On my unix-based system, I found that if I usd

I don't think your system IS `unix-based' (Unix is a trademark, and MacOS 
X is based on a rather different kernel).  It is quite possible that it is 
behaving differently from the POSIX description of Unix system calls on 
which R is based for Unix-alikes.

>       Sys.sleep( N )
> then cpu usage immediately went up drastically. If the the system is
> otherwise fairly idle, cpu usage goes up to nearly 100%. A cpu
> monitor shows that R is using the cpu cycles.
> If I use instead
>      system('sleep N')
> cpu usage does not go up.

Does that freeze the GUI?  It certainly freezes tcltk widgets on Unix.

> (where N is the number of seconds to sleep)
>>  version
>          _
> platform powerpc-apple-darwin7.9.0
> arch     powerpc
> os       darwin7.9.0
> system   powerpc, darwin7.9.0
> status
> major    2
> minor    1.1
> year     2005
> month    06
> day      20
> language R
> At 12:13 PM -0700 7/29/05, Tae-Hoon Chung wrote:
>> Hi, All;
>> I have a question. In R, what is the best way to make R idle for a while and
>> try something again later? For example, suppose there is an R job which
>> accesses a file that may be shared with other active jobs. So when the file
>> is being accessed by other job, your job will not be able to access the file
>> and your job will crash because of that. To avoid this, you want your job to
>> try to access the file repeatedly with some time interval, say every 10
>> seconds or something like that. Which is the best way to do this in R?

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list