This usually has to do with the caller (Matlab) and the callee (R) being
dynamically lined with different versions of dynamic libraries. On Linux
I work around this sort of thing by setting LD_LIBRARY_PATH to exactly
what I want when invoking R. E.g., instead of making the sh command
/usr/local/bin/R ...
to start R, try something like
LD_LIBRARY_PATH=/opt/sw/R/R-3.1.2/lib64/R/lib:/usr/local/lib64:/usr/lib
/usr/local/bin/R ...
where the value I give to LD_LIBRARY_PATH comes from calling
Sys.getenv("LD_LIBRARY_PATH") in a stand-alone R session.
I don't know the details of this on Apple's versions of Unix.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Fri, Feb 27, 2015 at 7:28 AM, Julian Keil <julian.keil at gmail.com>
wrote:
> Dear all,
>
> I have a Mac, OSX 10.7.5, run R 3.1.2 (2014-10-31) and Matlab R2013a
> (8.1.0.604).
>
> I try to call R from within Matlab to run a function in Batch mode.
> To do this, I followed this example:
>
> From: www.mathworks.com/matlabcentral/newsreader/view_thread/163726
>
> In an m-file you would have:
> ~~~~~~~~~~~~~~~~~~~~~
> data = sum(rand(100), 1);
> csvwrite('data.csv', data(:)); % Write as a column
> system('R CMD BATCH calc.R outputForDebugging.txt');
> testResults = csvread('testResults.csv');
> testResultsStruct = struct('W_statistic', testResults(1),
'p_value',
> testResults(2))
> ~~~~~~~~~~~~~~~~~~~~~
>
> In the calc.R r-file you would have:
> ~~~~~~~~~~~~~~~~~~~~~
> data <- read.table("data.csv", header = FALSE, sep =
",")
> results <- shapiro.test(data$V1)
> results2 <- c( results$statistic[["W"]], results$p.value )
> write.table(results2, file="testResults.csv", sep =
",", col.names > FALSE, row.names = FALSE, qmethod =
"double")
> ~~~~~~~~~~~~~~~~~~~~~
>
> Now, the R-Part in itself works fine. If I open R and run the
> calc.R-Script everything works. If I run the calc.R in Batch mode from the
> terminal, everything works.
> However, if I call R from within Matlab using the system command, I get
> the error:
>
> Error in dyn.load(file, DLLpath = DLLpath, ...) :
> kann shared object
>
'/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stats/libs/stats.so'
> nicht laden:
>
>
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stats/libs/stats.so,
> 6): Symbol not found: __gfortran_pow_r8_i4
> Referenced from:
> /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libRlapack.dylib
> Expected in:
> /Applications/MATLAB_R2013a.app/sys/os/maci64/libgfortran.2.dylib
> in
> /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libRlapack.dylib
> Beim Start - Warnmeldung:
> package 'stats' in options("defaultPackages") was not
found
>
> It appears that R fails to load some objects. However, I don't
understand
> why this only happens if I call R from Matlab, not when I start R by itself
> or use the terminal to start R.
> I already installed R new, but it did not help.
>
> Can anyone enlighten my on this matter?
>
> Thanks a lot!
>
> Julian
>
>
> ********************
> Dr. Julian Keil
>
> AG Multisensorische Integration
> Psychiatrische Universit?tsklinik
> der Charit? im St. Hedwig-Krankenhaus
> Gro?e Hamburger Stra?e 5-11, Raum E 307
> 10115 Berlin
>
> Telefon: +49-30-2311-1879
> Fax: +49-30-2311-2209
>
>
http://psy-ccm.charite.de/forschung/bildgebung/ag_multisensorische_integration
>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]