我想在特定时间运行R代码 [英] I want to run a R code at a specific time
本文介绍了我想在特定时间运行R代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在需要的特定时间运行R代码。
并且该过程完成后,我想终止R会话。
I want to run a R code at a specific time that I need. And after the process finished, I want to terminate the R session.
如果代码如下,则
tm<-Sys.time()
write.table(tm,file='OUT.TXT', sep='\t');
quit(save = "no")
我应该怎么做才能在以下位置运行此代码 2012-04-18 17:25:40。
我需要您的帮助。提前致谢。
What should I do to run this code at "2012-04-18 17:25:40". I need your help. Thanks in advance.
推荐答案
使用Windows的任务计划程序或 cron作业在Linux下。您可以在此处指定应在指定的特定时间运行的命令或程序。我肯定会不推荐R脚本,例如:
It is easiest to use the Task Scheduler of Windows, or a cron job under Linux. There you can specify a command or program that should be run at a certain time you specify. I would definitely not recommend an R script like:
time_to_run = as.POSIXct("2012-04-18 17:25:40")
while(TRUE) {
Sys.sleep(1)
if(Sys.time == time_to_run) {
## run some code
}
}
这篇关于我想在特定时间运行R代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文