我有一个R脚本,用于进行特定的Twitter搜索,并将结果连同时间戳添加到数据框中。我希望能够安排这个脚本每隔五分钟运行一次。有没有办法在R中实现这个功能?
回答:
如果你使用的是Linux机器,可以使用cron作业(链接在此)。在基于Windows的机器上,有一个名为任务计划程序的工具(链接在此)可以使用。通过这些工具,你可以调用RScript
,它允许你从命令行执行R脚本(在Linux上较旧版本的R可能需要使用R CMD
,如果是这样,我建议你更新R)。以下是Rscript
的帮助信息:
Usage: /path/to/Rscript [--options] [-e expr] file [args]--options accepted are --help Print usage and exit --version Print version and exit --verbose Print information on progress --default-packages=list Where 'list' is a comma-separated set of package names, or 'NULL'or options to R, in addition to --slave --no-restore, such as --save Do save workspace at the end of the session --no-environ Don't read the site and user environment files --no-site-file Don't read the site-wide Rprofile --no-init-file Don't read the user R profile --restore Do restore previously saved objects at startup --vanilla Combine --no-save, --no-restore, --no-site-file --no-init-file and --no-environ'file' may contain spaces but not shell metacharacters
包tcltk2也允许你使用tclTask
从正在运行的R控制台中安排任务。这也是一个值得考虑的选项。