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

Don MacQueen macq at llnl.gov
Sat Jul 30 00:52:48 CEST 2005


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
       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.

(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?
>
>Thanks in advance,
>
>Tae-Hoon Chung
>
>Post-Doctoral Researcher
>Translational Genomics Research Institute (TGen)
>445 N. 5th Street (Suite 530)
>Phoenix, AZ 85004
>1-602-343-8724 (Direct)
>1-480-323-9820 (Mobile)
>1-602-343-8840 (Fax)
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-help mailing list