【发布时间】:2018-04-13 21:42:00
【问题描述】:
我是编程和 R 的新手,但是,我正在尝试安装“xlsx”包(以及 XLConnect)以便通过 R 操作 Excel 文件。我正在运行 RStudio 版本 1.0.153,R Mac OSX 10.12.6 上的 3.4.2 版。
首先,我尝试使用install.packages('xlsx') 通过RStudio 安装包,并使用library('xlsx') 加载包。我收到了这个错误:
> library('xlsx')
Loading required package: rJava
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
Reason: image not found
Error: package ‘rJava’ could not be loaded
所以我尝试使用install.packages('rJava') 安装rJava 包并使用library('rJava') 加载它。
> library('rJava')
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
Reason: image not found
此外,我尝试通过此链接直接从 CRAN 下载并安装 rJava: https://cran.r-project.org/web/packages/rJava/index.html
我用下载的本地文件在 RStudio 中安装了这个,得到了这个结果:
> install.packages("~/Downloads/rJava_0.9-9 (1).tar.gz", repos = NULL, type = "source")
* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether clang accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files...
rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether clang supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver : '/usr/bin/jar'
compiler : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags : '-I/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/../include/darwin'
java libs : '-L/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/server -ljvm'
checking whether Java run-time works... yes
checking whether -Xrs is supported... yes
checking whether JNI programs can be compiled...
configure: error: Cannot compile a simple JNI program. See config.log for details.
Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.
ERROR: configuration failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’
Warning in install.packages :
installation of package ‘/Users/ivers1/Downloads/rJava_0.9-9 (1).tar.gz’ had non-zero exit status
我四处寻找解决这个问题的方法,我发现几个线程建议从终端 sudo r cmd javareconfig 运行以下代码,这应该会重置 Java 环境。但是,当我从终端运行此代码时,我得到以下结果:
> sudo r cmd javareconf
ARGUMENT 'cmd' __ignored__
ARGUMENT 'javareconf' __ignored__
R version 3.4.2 (2017-09-28) -- "Short Summer"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
...
...
...
终端忽略给定的参数,只返回 R 的版本信息。
现在我不知道该怎么办。有人对如何解决这个问题有建议吗?
【问题讨论】:
-
看看这个帖子:stackoverflow.com/questions/44157869/r-loading-rjava-error 看来这家伙和你有同样的问题,分两步解决了
-
如果您运行的是最新版本的 RStudio (v1.1.383),则应该解决此特定问题。
-
@KevinUshey;我已经尝试更新我的 RStudio 版本,并重复了我在原始帖子中描述的方法。但是,它没有任何区别,我仍然有同样的问题。 @用户1766682;这是我在发布问题之前尝试寻找解决方案的帖子之一。我的问题是安装和重新安装不同的 Java 版本对我没有任何影响,而且命令
sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib对我来说也没有任何进展。您对如何解决这个问题还有其他想法吗?
标签: java r rstudio osx-elcapitan rjava