I want to run an R script through stata. I can successfully open the script this way:
shell open -a RStudio "PATHWAY/filename.R"
And in terminal, I can successfully run the script through the command:
Rscript "PATHWAY/filename.R"
I thought that shell
allowed me to pass Stata terminal commands. However, shell Rscript "PATHWAY/filename.R"
returns the error /bin/bash: Rscript: command not found
.
I see that others execute R scripts via something like
shell "C:\Program Files\R\R-2.15.1\bin\x64\R.exe" CMD BATCH test.R
However, I am unsure about the equivalent R command pathway on my Mac. (Or why I need a pathway at all, since I can execute the file in terminal w/ the mere command Rscript, and can open the file w/ shell in stata, without a pathway.) Following notes here, I find that file.path(R.home("bin"), "R")
returns "/Library/Frameworks/R.framework/Resources/bin/R"
, but adding this path way to the command (shell /Library/Frameworks/R.framework/Resources/bin/R/R.exe "PATHWAY/filename.R"
) doesn't help at all.
Additionally, I am aware of the Rsource package, but I think this is more capability than I need. I don't want to run the R code within Stata, or import R objects into Stata after running. I merely want Stata to tell terminal "Run this particular R script," and then wait for the run to complete before continuing on with the Stata code. So I think shell is the right avenue, if I can get it to work.
Would appreciate mac-specific advice! Cross-posted on Statalist.
Leah