[R] How to make R automatic?

Peter Ehlers ehlers at ucalgary.ca
Tue Jun 1 17:35:30 CEST 2010


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



More information about the R-help mailing list