首页 > 解决方案 > 如何使用 taskscheduleR 自动化 R 中的脚本?

问题描述

我目前正在查看此文档,以使用 R 和 taskscheduleR 在我的机器上自动执行脚本。我对以下文档感到困惑:

在文档中的示例中,什么是“extdata”,这应该是我的 R 脚本的文件路径,而“helloworld.R”是实际的 R 脚本吗?

myscript <- system.file("extdata", "helloworld.R", package = "taskscheduleR")

我目前对此的看法如下: C:/Users/santi/Documents/R Scripts 是我的文件路径,Wayerhaeuser_Automation_script.R 是我的实际 R 脚本

myscript <- system.file("C:/Users/santi/Documents/R Scripts", "Wayerhaeuser_Automation_script.R", package = "taskscheduleR")

taskscheduler_create(taskname = "myfancyscript", rscript = myscript, 
                     schedule = "ONCE", starttime = format(Sys.time() + 62, "%H:%M"))

我对它的文档有点困惑。

尝试提出的解决方案后尝试: 在此处输入图像描述

标签: rautomationtaskschedulerwindows-task-scheduler

解决方案


更改myscript为:

myscript <- paste0("C:/Users/santi/Documents/R Scripts/","Wayerhaeuser_Automation_script.R")

它应该可以正常工作。该rscript参数只是要运行的文件的字符串路径。如果有空格,有时路径会被错误地解释,所以如果它不起作用,还可以尝试将文件夹名称更改为 R_Scripts


推荐阅读