I have a continous process that collects data, and I want to write the data that were collected every hour. Simply, how can I conditionally save data every hour to an .Rdata file.
For context, I collect data in a list, wish to save the list object to an hourly file, remove the list, and rebuild it.
I tried the code below but it did not work:
if (identical(format(Sys.time(), "%M:%S"), "00:00")) {
save(twt, file=fname_r)
}
Any help will be much appreciated.
You may be going about this in the wrong way. Not everything is a job for R (given that R really is single-threaded), and scheduling has always been a key operating system task. Use
cron, or if you’re on that market-leading OS from the Northwest, look into its scheduling options. Then setup a trivial Rscript file.Have the continuous collection process run to collect, and to dump results somewhere, either in ascii or binary. Then have an hourly job collecting the most recent dumps. That can well be done in R once you figured the scheduling out.
As for the narrower question of deciding whether an hour has passed, use something like