简体   繁体   English

在macOS Mavericks 10.9.5上安装xlsx和rJava

[英]Install xlsx and rJava on macOS Mavericks 10.9.5

Its being a real nightmare to install rjava on my Mac. 在我的Mac上安装rjava是一个真正的噩梦。

My setup: 我的设置:

MacOS 10.9.5
Java: 7u71 (64 bits dowloaded from Oracle site)
R: R version 3.1.1 (2014-07-10)

First, in the command line I ran the 首先,在命令行中我运行了

sudo R CMD javareconf

Then, I ran inside R: 然后,我在里面跑了R:

install.packages('rJava')

The error in the end of the compiling is this: 编译结束时的错误是这样的:

JavaVM -F/opt/local/Library/Frameworks/R.framework/.. -framework R -llzma -lm -liconv -licuuc -licui18n
ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/Users/costa/Library/R/3.1/library/rJava’

I tried Java 8 and the Mac default java and also got the same error. 我尝试了Java 8和Mac默认的java也得到了同样的错误。

Ideias? Ideias?

What I did (using macports R) as root (sudo bash): 我做了什么(使用macports R)作为root(sudo bash):

  • edit /opt/local/Library/Frameworks/R.framework/Resources/etc/Makeconf and change the line 编辑/opt/local/Library/Frameworks/R.framework/Resources/etc/Makeconf并更改行

     LIBS = -llzma -lm -liconv -licuuc -licui18n 

    to

     LIBS = -llzma -lm -liconv 
  • install the original 1.6 Mac Java 安装原始的1.6 Mac Java

  • export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

  • run R CMD javareconf 运行R CMD javareconf

Now you can start R and do a install.packages("rJava") . 现在你可以启动R并执行install.packages("rJava") Using the 1.6 version of Java made sure that also RStudio can load the rJava package. 使用1.6版本的Java确保RStudio也可以加载rJava包。

If you do not plan using RStudio, you can also use Java 1.8 如果您不打算使用RStudio,也可以使用Java 1.8

I had the same error on my computer (Mac OS 10.9.5, Java 1.8.0_11, R 3.1.1). 我的计算机上出现了同样的错误(Mac OS 10.9.5,Java 1.8.0_11,R 3.1.1)。 Installing the newest Java JDK from Oracle (1.8.0_25) didn't solve the problem (yet). 从Oracle(1.8.0_25)安装最新的Java JDK并没有解决问题。 However, after updating Java, installing R 3.1.2 solved the problem for me. 但是,在更新Java之后,安装R 3.1.2解决了我的问题。 After running install.packages("rJava") , this works: 运行install.packages("rJava") ,这有效:

> library("rJava")
> .jinit() # this starts the JVM
> s <- .jnew("java/lang/String", "Hello World!")
> .jcall(s,"I","length")
[1] 12

Do note that updating the JDK is something different from the Java version in the GUI Java Control Panel, accessible through the System preferences. 请注意,更新JDK与GUI Java控制面板中的Java版本不同,可通过“系统”首选项访问。 The latter is only the JRE for the internet browser plugin. 后者只是互联网浏览器插件的JRE

I was actually able to avoid editing my environment completely by using the Mac binary to install rJava on my Macbook (running OSX Yosemite and R version 3.2.3). 我实际上可以通过使用Mac二进制文件在我的Macbook上安装rJava(运行OSX Yosemite和R版本3.2.3)来完全避免编辑我的环境。 First, do the following in R to install rJava: 首先,在R中执行以下操作以安装rJava:

install.packages("rJava", type = "mac.binary")

Presumably independent of this, for some reason I couldn't install xlsx until I first installed the xlsxjars dependency. 大概是独立于此,由于某种原因,在我第一次安装xlsxjars依赖项之前,我无法安装xlsx。 So do the following in R: 在R中执行以下操作:

install.packages(c("xlsxjars", "xlsx"))

And with those two commands, xlsx appears to install just fine on a mac! 使用这两个命令,xlsx似乎在mac上安装得很好!

This worked for me: 这对我有用:

sudo R CMD javareconf

Then, in the R interpretor: 然后,在R解释器中:

install.packages('rJava', type='source')
install.packages('xlsx', type='source')

I had the same issue. 我遇到过同样的问题。 I'm using OS X Yosemite and initially had installed R through homebrew 我正在使用OS X Yosemite,最初通过自制软件安装了R.

I performed the following steps to fix it: 我执行了以下步骤来修复它:

  1. Closed all instances of R 关闭R的所有实例
  2. In my terminal shell, ran sudo R CMD javareconf 在我的终端shell中,运行了sudo R CMD javareconf
  3. Opened up R from my terminal and ran: 从我的终端打开R并运行:

    install_packages("rJava")

    install_packages("xlsx")

Using the old Java SE 6 I was able to get rJava compiled by running javareconf as follows: 使用旧的Java SE 6,我可以通过运行javareconf来编译rJava,如下所示:

JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home \
JAVA_CPPFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/ \
r CMD javareconf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM