【发布时间】:2018-09-02 03:31:11
【问题描述】:
关于如何执行此操作的信息并不多。我尝试在网上研究了一个博客,并在VBA中实现了以下代码(带有R文件的路径):-
Sub RunRscript()
'runs an external R code through Shell
'The location of the RScript is 'C:\R_code'
'The script name is 'hello.R'
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_code\hello.R"
errorCode = shell.Run(path, style, waitTillComplete)
End Sub
但是,当我在 Excel 中运行宏时,它基本上什么都不做——只是在 RStudio 中打开脚本。我没有收到任何错误,但它没有提供任何输出 - 只需在 Rstudio 中打开 R 脚本。我做错了什么?
另外,如果我需要在Excel中使用R,这种方法是否有效或者基本上我需要安装软件RExcel?
在 Excel 中使用 R 的任何其他链接/信息将不胜感激。谢谢:)
【问题讨论】:
-
通过 cmd.exe 运行“RScript C:\R_code\hello.R”会发生什么?
-
同样的事情,我上面描述的-只是在RStudio中打开
-
Running R scripts from VBA 可能重复所以这段代码看起来是正确的。
-
已经试过了。
-
我猜在 Windows 上你不能简单地调用这样的可执行文件。与可执行文件 C:\Program Files\R\R-3.4.0\bin\x64\Rscript.exe C:\R_code\hello.R 的路径类似的东西怎么样