I want to run R code in RStudio by just clicking a button in excel. Currently, I could only open the R code in RStudio. How do I run this R code which is open in RStudio from VBA?
Sub RunRScript()
Dim WshShell, strCurDir
Set WshShell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 1
Dim errorCode As Integer
Dim path As String
DirFile = C:\Program Files\RStudio\bin\rstudio.exe
RCodePath = D:\rCode.R
path = Chr(34) & DirFile & Chr(34) & " " & Chr(34) & RCodePath & Chr(34)
errorCode = WshShell.Run(path, style, waitTillComplete)
End Sub
I tried running the rcode using rscript.exe. But some of the r modules are not working when I use rscript.exe. The rcode works fine when I run on RStudio IDE. So I'm trying to open rstudio and run the rcode.