I am working on a project where I need to run an R script within Stata. I have the following code written:
shell "/Users/alexanderrbilly/Desktop/Neel/cleaner.R" CMD BATCH "cleaner.R"
Despite even changing the command directory before this (which shouldn't matter), I keep getting the same error:
/bin/bash: /Users/alexanderrbilly/Desktop/Neel/cleaner.R: Permission denied
Let me know if I'm doing something erroneous or how I may get around this issue.
答案 0 :(得分:1)
您的命令行不正确。
您的字符串"/Users/alexanderrbilly/Desktop/Neel/cleaner.R"
应该是R可执行文件的路径。
如果您使用的是Windows。假设文件K:\tmp\random.R
包含代码write.csv(rnorm(10), "a.csv")
。
然后,你可以写在Stata:
cd K:\tmp
shell C:\APPLI\R\R-3.4.1\bin\x64\R.exe CMD BATCH random.R
当然,请更改R可执行文件的路径以适合您的安装。
如果您使用的是Linux,则错误可能来自cleaner.R
没有execute permission这一事实。您也可以查看What's the best way to use R scripts on the command line (terminal)?