Running R Script within Stata - "permission denied"

时间:2017-08-04 12:28:36

标签: r shell stata

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.

1 个答案:

答案 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)?