Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:如何设置JDK与R一起工作(相关:rJava、RStudio、xslx)_Java_R_Rstudio_Osx Elcapitan_Rjava - Fatal编程技术网

R:如何设置JDK与R一起工作(相关:rJava、RStudio、xslx)

R:如何设置JDK与R一起工作(相关:rJava、RStudio、xslx),java,r,rstudio,osx-elcapitan,rjava,Java,R,Rstudio,Osx Elcapitan,Rjava,我对编程和R都是新手,但是,我正在尝试安装“xlsx”软件包(以及XLConnect),以便通过R操作Excel文件。我正在Mac OSX 10.12.6上运行RStudio版本1.0.153,R版本3.4.2 首先,我尝试通过RStudio使用install.packages('xlsx')安装包,并使用library('xlsx')加载包。我得到了这个错误: > library('xlsx') Loading required package: rJava Error: package

我对编程和R都是新手,但是,我正在尝试安装“xlsx”软件包(以及XLConnect),以便通过R操作Excel文件。我正在Mac OSX 10.12.6上运行RStudio版本1.0.153,R版本3.4.2

首先,我尝试通过RStudio使用
install.packages('xlsx')
安装包,并使用
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')
加载它

此外,我尝试通过以下链接直接从CRAN下载并安装rJava:

我使用下载的本地文件在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
我四处搜索以获得这个问题的解决方案,发现几个线程建议从Terminal
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的版本信息


现在我不知道该怎么办。有人对如何解决这个问题有什么建议吗?

我也有同样的问题。我更新了我的RStudio并再次安装了软件包。这对我来说很有吸引力。

我使用了RStudio提供的命令。注意大小写,因为该命令区分大小写:

sudo R CMD javareconf

看看这个帖子:看起来这个家伙和你有同样的问题,并且分两步解决了。如果你运行的是最新版本的RStudio(v1.1.383),这个问题应该得到解决。@KevinUshey;我尝试过更新我的RStudio版本,并重复了我在原始帖子中描述的方法。然而,这没有任何区别,我仍然有同样的问题@用户1766682;这是我在发布问题之前试图找到解决方案的帖子之一。我的问题是,安装和重新安装不同的Java版本对我没有任何影响,而且命令
sudo ln-f-s$(/usr/libexec/Java_home)/jre/lib/server/libjvm.dylib/usr/local/lib
对我没有任何影响。你对如何解决这个问题还有什么想法吗?看看这里:你不需要
sudo
sudo R CMD javareconf