关于如何做到这一点的信息并不多。我尝试在线学习博客并在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 的链接/信息将不胜感激。谢谢:)