带有OS Sierra的R(3.4.1)中的rJava加载 [英] rJava loading in R(3.4.1) with OS Sierra

查看:79
本文介绍了带有OS Sierra的R(3.4.1)中的rJava加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在最新版本的R(3.4.1),Mac(10.12.5)和Java VM(1.8.0_131,x86_64 :)中遇到了rJava的问题

问题:

我尝试按照本指南进行操作

I try it to follow this guide

scottdhoover.wordpress.com/2013/03/05/a-basic-rjava-example/

scottdhoover.wordpress.com/2013/03/05/a-basic-rjava-example/

为了能够在R中运行rJava.

To be able to run rJava in R.

r中的一些代码:

库(rJava) .jinit(") .jclassPath() [1]"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java"

library(rJava) .jinit("") .jclassPath() [1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java"

s<-.jnew("java/lang/String","Hello World!") .jcall(s,"I","length") [1] 12

s <- .jnew("java/lang/String", "Hello World!") .jcall(s, "I", "length") [1] 12

实际上正在工作..但是当我尝试使用我的文件时:

So is actually working.. but when I try with my files:

.jaddClassPath("/Users/Camilo/Desktop/20170711_Java2R") .jclassPath() [1]"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java""/Users/Camilo/Desktop/20170711_Java2R"

.jaddClassPath("/Users/Camilo/Desktop/20170711_Java2R") .jclassPath() [1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java" "/Users/Camilo/Desktop/20170711_Java2R"

myExchange<-.jnew("myExchange") .jnew("myExchange")中的错误:java.lang.ClassNotFoundException

myExchange <- .jnew("myExchange") Error in .jnew("myExchange") : java.lang.ClassNotFoundException

文件myExchange.java与指南中的文件相同,并且位于桌面的文件夹中.

where the file myExchange.java is the same that in the guide and is in the folder in the Desktop.

我所做的事情:

基本上,我尝试从R安装rJava,但没有用.然后,我遵循了两个指南,能够从源代码中将RJava包r

Basically I tried to instal rJava from R and didn't work. Then I have follow two guides to be able to load the package rJava in R from source

我已遵循本指南:

https://github.com/snowflakedb/dplyr-snowflakedb/wiki/Configuring-R-rJava-RJDBC-on-Mac-OS-X (能够加载rJava)

https://github.com/snowflakedb/dplyr-snowflakedb/wiki/Configuring-R-rJava-RJDBC-on-Mac-OS-X (To be able to load rJava)

两者都

   R CMD javareconf
   /usr/libexec/java_home -V

看起来完全一样.

要摆脱人们通常遇到的OpenMP问题,请遵循以下指南:

To get rid of the OpenMP problem that people normally have I follow this guide:

http://thecoatlessprofessor.com/programming/openmp-in-r-on-os-x/#clang-before-3-4-0 (摆脱所有人都有的OpenMP问题).

http://thecoatlessprofessor.com/programming/openmp-in-r-on-os-x/#clang-before-3-4-0 (To get rid with the OpenMP problem that all people have).

最后,我使用此代码创建符号链接

and Finally I create a symlink using this code

  sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib

并且我能够从R安装库.

and I was able to install the library from R.

但是!当我从终端尝试时,出现此错误

But! When I try it from terminal I get this error

   ld: library not found for -lomp
   clang-4.0: 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’

所以我坚强:库或符号链接也必须丢失..但是没有llvm中的文件(已经在llvm中使用

So I tought: A library or a symlink must to be missing too.. but there is not such a file as in llvm ( Have been solve in llvm with ld: library not found for -lomp )

我知道错误"ClassNotFoundExceptions"可能与PATH有关,但应该可以,因为开始时已经声明了cos.

I know that the error "ClassNotFoundExceptions" could be related with the PATH but It should be OK cos has been declared at the beginning.

顺便说一句,我还检查了如下所示的.R/Makevars文件

btw, I also check the .R/Makevars file that looks like this

  CC=/usr/local/clang4/bin/clang    
  CXX=/usr/local/clang4/bin/clang++
  LDFLAGS=-L/usr/local/clang4/lib

任何想法如何解决?提前致谢!我希望这很清楚.

Any ideas how to solve it? Thanks in advance! I hope that is clear.

推荐答案

对我来说,解决方案是安装

For me the solution was to install https://github.com/coatless/r-macos-clang and add link

sudo ln -s /usr/local/clang4/lib/libomp.dylib /usr/local/lib/libomp.dylib

R CMD javareconfunset JAVA_HOME之前.

这篇关于带有OS Sierra的R(3.4.1)中的rJava加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆