Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在不使用任务调度器的情况下调度R脚本_R_Excel_Vba_Vbscript_Taskscheduler - Fatal编程技术网

在不使用任务调度器的情况下调度R脚本

在不使用任务调度器的情况下调度R脚本,r,excel,vba,vbscript,taskscheduler,R,Excel,Vba,Vbscript,Taskscheduler,我的Windows 7计算机上安装了RStudio,但是我无法访问Windows任务计划程序来自动执行一些R脚本。在这种情况下,还有其他选择吗?我研究了taskscheduleR,但发现这只是任务调度器的包装。开放使用VB脚本的想法-基本上任何黑客都可以。我建议您使用VBA来完成任务,您需要学习如何使用应用程序。OnTime 你需要其他潜水艇,根据你的意愿触发和停止这个潜水艇;首先可以开始安排日程 Public stop_running As Boolean Public sTime As St

我的Windows 7计算机上安装了RStudio,但是我无法访问Windows任务计划程序来自动执行一些R脚本。在这种情况下,还有其他选择吗?我研究了
taskscheduleR
,但发现这只是任务调度器的包装。开放使用VB脚本的想法-基本上任何黑客都可以。

我建议您使用VBA来完成任务,您需要学习如何使用
应用程序。OnTime

你需要其他潜水艇,根据你的意愿触发和停止这个潜水艇;首先可以开始安排日程

Public stop_running As Boolean
Public sTime As String

Sub Start(input As String)

    stop_running = True 'This controls schedule in Application.Ontime
    sTime = input
    Application.OnTime TimeValue(sTime), "Rscript", Schedule:=stop_running

End Sub
每当您要停止运行此宏时,您都可以运行此宏

Sub Finish()

    stop_running = False 'Set the schedule to false to stop the macro
    Application.OnTime TimeValue(sTime), "Rscript", Schedule:=stop_running

End Sub
然后,这是运行r脚本的子脚本:

Sub Rscript()
'runs R script through cmd

    If Not stop_running Exit Sub

Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 1
Dim errorCode As Integer
Dim path As String

path = "RScript C:\R\myscript.R"
errorCode = shell.Run(path, style, waitTillComplete)

End Sub
您可以从即时窗口调用宏
Start
,如下所示:

Call Start(TimeValue("14:00:00 pm"))

您的宏将在每天下午2点运行。

我建议您使用VBA执行任务,您需要学习如何使用
应用程序。OnTime

你需要其他潜水艇,根据你的意愿触发和停止这个潜水艇;首先可以开始安排日程

Public stop_running As Boolean
Public sTime As String

Sub Start(input As String)

    stop_running = True 'This controls schedule in Application.Ontime
    sTime = input
    Application.OnTime TimeValue(sTime), "Rscript", Schedule:=stop_running

End Sub
每当您要停止运行此宏时,您都可以运行此宏

Sub Finish()

    stop_running = False 'Set the schedule to false to stop the macro
    Application.OnTime TimeValue(sTime), "Rscript", Schedule:=stop_running

End Sub
然后,这是运行r脚本的子脚本:

Sub Rscript()
'runs R script through cmd

    If Not stop_running Exit Sub

Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 1
Dim errorCode As Integer
Dim path As String

path = "RScript C:\R\myscript.R"
errorCode = shell.Run(path, style, waitTillComplete)

End Sub
您可以从即时窗口调用宏
Start
,如下所示:

Call Start(TimeValue("14:00:00 pm"))

您的宏将在每天下午2点运行。

我如何让它每天下午2点运行而不进行干预?@Scottorvath更新了答案。我如何让它每天下午2点运行而不进行干预?@Scottorvath更新了答案。