2

我曾经能够通过系统调用从 Matlab 调用 R:

system('"/usr/bin/R" --no-save < myscript.R')

但是现在,使用 Matlab R2012b 和 R 版本 3.0.0 (2013-04-03) - “Masked Marvel”,我在加载库时遇到错误,即使当我从 shell 运行它时一切正常。我正在运行 MacOSX 10.6.8。

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
unable to load shared object'/Library/Frameworks/R.framework/Versions/3.0/Resources/library/stats/libs/stats.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.0/Resources/library/stats/libs/stats.so, 6):
Symbol not found: __gfortran_pow_r8_i4
Referenced from: /Library/Frameworks/R.framework/Versions/3.0/Resources/lib/libRlapack.dylib
Expected in: /Applications/MATLAB_R2012b.app/sys/os/maci64/libgfortran.2.dylib
in /Library/Frameworks/R.framework/Versions/3.0/Resources/lib/libRlapack.dylib
During startup - Warning message:
   package 'stats' in options("defaultPackages") was not found 
4

1 回答 1

8

DYLD_LIBRARY_PATH在调用 R 脚本之前取消设置环境变量:

>> !/usr/bin/Rscript ms.R
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.0/Resources/library/stats/libs/stats.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.0/Resources/library/stats/libs/stats.so, 6): Symbol not found: __gfortran_pow_r8_i4
  Referenced from: /Library/Frameworks/R.framework/Versions/3.0/Resources/lib/libRlapack.dylib
  Expected in: /Applications/MATLAB_R2013a.app/sys/os/maci64/libgfortran.2.dylib
 in /Library/Frameworks/R.framework/Versions/3.0/Resources/lib/libRlapack.dylib
During startup - Warning message:
package 'stats' in options("defaultPackages") was not found 
Error: could not find function "rnorm"
Execution halted

>> !unset DYLD_LIBRARY_PATH; /usr/bin/Rscript ms.R

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept)            x  
   -0.09727      0.03573  
于 2013-07-15T08:32:18.737 回答