Hello, I have a question about how R can run automatically. Here is the story: A file called "data.csv" will be generated every couple of minutes in a folder (overwrite itself). What I want R to do is: 1) scan the folder to find the file. 2) if the file is a newly generated file, process the file 3) output some file identifier on the screen, such as the time when the file was generated. 4) pause for 20 seconds (doesnt need to be precise) and repeat 1) Idealy, I would like R to do this everyday from 9:00am to 6:00pm. What I got so far is: I can use list.files() and file.info to get 1) and 2). For 4), I can write some trivial loop to kill some time, but I would like to be more accurate tham that, considering different PC running the loop. I have no idea about 3). Any suggestion/better solution? Thank you very much!! Best regards, Ted -- View this message in context: http://r.789695.n4.nabble.com/How-to-make-R-automatic-tp2238541p2238541.html Sent from the R help mailing list archive at Nabble.com.
?Sys.sleep On Tue, 1 Jun 2010, zhangted001 wrote:> > Hello, I have a question about how R can run automatically. Here is the > story: > > A file called "data.csv" will be generated every couple of minutes in a > folder (overwrite itself). What I want R to do is: > > 1) scan the folder to find the file. > 2) if the file is a newly generated file, process the file > 3) output some file identifier on the screen, such as the time when the file > was generated. > 4) pause for 20 seconds (doesnt need to be precise) and repeat 1) > > Idealy, I would like R to do this everyday from 9:00am to 6:00pm. > > What I got so far is: I can use list.files() and file.info to get 1) and 2). > For 4), I can write some trivial loop to kill some time, but I would like to > be more accurate tham that, considering different PC running the loop. I > have no idea about 3). > > Any suggestion/better solution? > > Thank you very much!! > > Best regards, > Ted > > > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/How-to-make-R-automatic-tp2238541p2238541.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
On 2010-06-01 8:07, zhangted001 wrote:> > Hello, I have a question about how R can run automatically. Here is the > story: > > A file called "data.csv" will be generated every couple of minutes in a > folder (overwrite itself). What I want R to do is: > > 1) scan the folder to find the file. > 2) if the file is a newly generated file, process the file > 3) output some file identifier on the screen, such as the time when the file > was generated. > 4) pause for 20 seconds (doesnt need to be precise) and repeat 1) > > Idealy, I would like R to do this everyday from 9:00am to 6:00pm. > > What I got so far is: I can use list.files() and file.info to get 1) and 2). > For 4), I can write some trivial loop to kill some time, but I would like to > be more accurate tham that, considering different PC running the loop. I > have no idea about 3).For (3), assign the value of file.info: fi <- file.info("data.csv") print(fi[, "mtime"]) For (4) see help(Sys.sleep) -Peter Ehlers> > Any suggestion/better solution? > > Thank you very much!! > > Best regards, > Ted
?difftime ?file.info file.info(filename)$mtime Sys.sleep(20) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.list at gmail.com On Jun 1, 2010, at 10:07 AM, zhangted001 wrote:> > Hello, I have a question about how R can run automatically. Here is > the > story: > > A file called "data.csv" will be generated every couple of minutes > in a > folder (overwrite itself). What I want R to do is: > > 1) scan the folder to find the file. > 2) if the file is a newly generated file, process the file > 3) output some file identifier on the screen, such as the time when > the file > was generated. > 4) pause for 20 seconds (doesnt need to be precise) and repeat 1) > > Idealy, I would like R to do this everyday from 9:00am to 6:00pm. > > What I got so far is: I can use list.files() and file.info to get 1) > and 2). > For 4), I can write some trivial loop to kill some time, but I would > like to > be more accurate tham that, considering different PC running the > loop. I > have no idea about 3). > > Any suggestion/better solution? > > Thank you very much!! > > Best regards, > Ted > > > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/How-to-make-R-automatic-tp2238541p2238541.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
Thank you all for the information! That is exactly what I was looking for. -- View this message in context: http://r.789695.n4.nabble.com/How-to-make-R-automatic-tp2238541p2244132.html Sent from the R help mailing list archive at Nabble.com.
---------- Forwarded message ---------- From: Adel ESSAFI <adel.safi@imag.fr> Date: 2010/6/5 Subject: Re: [R] How to make R automatic? To: zhangted001 <zhengly@gmail.com> Well, I am new but i will give you an example of script that I run cat exec2.sh R --no-save << EOF fl=list.files(pattern="*.dat") for( j in 1:length(fl)){ a=read.table(fl[j]) debut=a[,1] fin=a[,2] duree=a[,3] u=matrix(ncol=1,nrow=length(fin)-1) for( i in 1:length(fin)-1) u[i]=debut[i+1]-fin[i] if (! (is.na(mean(duree)) || is.na(sd(duree)) || is.na(mean(u)) || is.na(sd(u) ) ) ) { cat (fl[j]," ",mean(duree)," ",sd(duree)," ",mean(u)," ",sd(u)," ",trunc((mean(duree)/(mean(duree)+mean(u)))*100)," ",length(debut), "\n",file="testlogsnavai",append=TRUE) } } This works perfect 2010/6/5 zhangted001 <zhengly@gmail.com>> Thank you all for the information! That is exactly what I was looking for. > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-make-R-automatic-tp2238541p2244132.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >-- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 -- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 [[alternative HTML version deleted]]