"/bin/bash: R: command not found" when trying to run R from MATLAB (mac)

1 回表示 (過去 30 日間)
Kouichi C. Nakamura
Kouichi C. Nakamura 2017 年 3 月 4 日
コメント済み: Walter Roberson 2017 年 3 月 6 日
I'm trying to call R from MATLAB (R2016b/R2017a prerelease) on macOS (10.12 Siera).
I've installed R and on Terminal.app, command "R" results in loanching R software successfully.
In my understanding, something like this in MATLAB command window should do the job.
> system('R CMD BATCH "script1.R"');
However, simply "system('R')" in MATLAB returns an error message as below (let alone more complicated "system('R CMD BATCH "script1.R"')"):
>> system('R')
/bin/bash: R: command not found
ans =
127
I'm a little puzzled because the same "R" command works in Terminal and I thought "system('R')" or "unix('R')" in MATLAB is equivalent.
Can anybody suggest a solution?
For Windows, I have found a solution here. You need to properly change Environment Variables. But what about macOS?

採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 4 日
In OS-X, because applications launched from the dock do not go through a login shell, the full shell initialization files are not used, so the PATH environment variable will probably not be the same.
You can either use the full path to R or you can setenv('PATH') to include the path to R, or you can alter the OS-X environment variables.
You might be able to modify /etc/paths but I am not sure that works in newer versions.
  4 件のコメント
Kouichi C. Nakamura
Kouichi C. Nakamura 2017 年 3 月 6 日
Thanks. This (below) does not work either. In fact, "/usr/local/bin" is already found in $PATH, so I don't quite see why simply "system('R')" doesn't work.
export PATH=/usr/local/bin:$PATH
launchctl setenv PATH $PATH
Walter Roberson
Walter Roberson 2017 年 3 月 6 日
On OS-X El Capitan, /usr/local/bin is not part of the default path given to apps.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by