【发布时间】:2019-09-17 13:38:19
【问题描述】:
我正在尝试从 excel VBA 运行 R 脚本。该脚本只是查询数据、格式化和组织数据,然后将其导出为单独的 XLS 文件。但是,我无法运行 R 脚本。
离开这篇文章:(尽管我理解的是 OG 代码) Running R from Excel VBA without RExcel 由于下载工作限制,我无法访问 RExcel。我找到了我的 R.exe 文件路径,并且下面的宏能够运行:
Dim rCommand As String
rCommand = "C:\Program Files\R\R-3.5.3\bin\R.exe --verbose U:\Reporting\Mix of Business Report\Morgan's Trials\Mix of Business Report v1.R"
'Timer Set to run full Model.R script
Application.Wait Now + TimeValue("00:01:05")
'Runs R Script and Arguments into process
shell rCommand, vbNormalFocus
'Timer Set to run full Model.R Script
Application.Wait Now + TimeValue("00:01:05")
我希望我的宏在后台运行,但是 R 窗口(不是 Rstudio,只要它可以工作就可以)不运行 R 脚本。
这是我在“Rterm”窗口中显示的内容:
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
ARGUMENT 'U:\Reporting\Mix' __ ignored__
ARGUMENT 'of' __ ignored__
ARGUMENT 'Business' __ ignored__
ARGUMENT 'Report\Morgan's' __ ignored__
ARGUMENT 'Trials\Mix' __ ignored__
ARGUMENT 'of' __ ignored__
ARGUMENT 'Business' __ ignored__
ARGUMENT 'Report' __ ignored__
ARGUMENT 'v1.R' __ ignored__
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("C:/Program Files/R/R-3.5.3/library/methods/libs/x64/methods.dll") ...
'verbose' and 'quietly' are both true; being verbose then ..
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("C:/Program Files/R/R-3.5.3/library/utils/libs/x64/utils.dll") ...
'verbose' and 'quietly' are both true; being verbose then ..
Garbage collection 1 = 0+0+1 (level 2) ...
11.5 Mbytes of cons cells used (35%)
2.7 Mbytes of vectors used (4%)
now dyn.load("C:/Program Files/R/R-3.5.3/library/grDevices/libs/x64/grDevices.dll") ...
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("C:/Program Files/R/R-3.5.3/library/graphics/libs/x64/graphics.dll") ...
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("C:/Program Files/R/R-3.5.3/library/stats/libs/x64/stats.dll") ...
ending setup_Rmainloop(): R_Interactive = 1 {main.c}
>R_ReplConsole(): before "for(;;)" {main.c}
为什么我的文件路径被忽略了?我还尝试将详细 r 脚本路径的反斜杠更改为正斜杠,同样的消息。
对不起,如果它是重复的,我不明白发布的任何其他问题,上面链接的问题是我最好的选择。
【问题讨论】:
-
看起来一个问题是文件名中的空格。确保以适合您的操作系统的方式正确转义它们,以免它们看起来像命令行上的单独参数。
-
说得通!我该怎么做?