我只想尝试使用rJava从R中访问自定义java类的简单示例.
HelloWorld.java
class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World!");
}
}
Run Code Online (Sandbox Code Playgroud)
将.java编译为.class如下:
javac HelloWorld.java
Run Code Online (Sandbox Code Playgroud)
R代码(从HelloWorld.java和HelloWorld.class的相同目录运行.
library(rJava)
> .jinit()
[1] 0
> .jnew("HelloWorld")
Error in .jnew("HelloWorld") : java.lang.ClassNotFoundException
Run Code Online (Sandbox Code Playgroud)
谢谢你的任何指示.
我想将一个R脚本运行到eclipse中.
罐子:
环境(运行 - >运行配置 - >环境)
码:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
import org.rosuda.JRI.Rengine;
public class HelloWorldApp {
public static void main(String[] args) throws RserveException, REXPMismatchException, FileNotFoundException, IOException {
RConnection c = new RConnection("localhost",6311);
if(c.isConnected()) {
System.out.println("Connected to RServe.");
if(c.needLogin()) {
System.out.println("Providing Login");
c.login("username", "password");
}
REXP x = c.eval("1:10");
for(int i=0;i < x.length();i++)
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用64位Windows 7和64位R 3.2.0。我已经下载了rJava软件包,但是它给出了如下错误。
错误:.onLoad在'rJava'的loadNamespace()中失败,详细信息:
调用:dirname(this $ RuntimeLib)错误:预期使用字符向量参数另外:警告消息:软件包'rJava'是在R版本3.2.2下构建的错误:“ rJava”的程序包或名称空间加载失败
我在stackoverflow上搜索了答案,并执行以下操作:
1)将jvm.dll文件添加到我的PATH变量中,即在以下目录中:
C:\Program Files\Java\jdk1.8.0_25\jre\bin\
Run Code Online (Sandbox Code Playgroud)
2)我正在使用64位R 3.2.0,并检查JVM版本是否为64位,请在命令行中键入以下内容:
java -d64 -version
Run Code Online (Sandbox Code Playgroud)
它给出了以下输出:
C:\Users\xyz> java -d64 -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
Run Code Online (Sandbox Code Playgroud)
因此,至少JVM与R匹配。
那么还需要做更多的rJava工作吗?我还检查了我的PATH变量,看来还可以。
里面rocker/tidyverse:3.3.2即使我安装 r-cran-rjava r-cran-nloptr没有错误,无论是包装rJAva,并nloptr在R缺少任何想法,为什么?
看下面的Docker文件:
FROM rocker/tidyverse:3.3.2
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get -y update && apt-get install -y \
default-jdk r-cran-rjava r-cran-nloptr libssh2-1-dev
RUN R -e "library('rJava')" # Error in library("rJava") : there is no package called ‘rJava’
RUN R -e "library('nloptr')" # Error in library("nloptr") : there is no package …Run Code Online (Sandbox Code Playgroud) 我试图在OpenSUSE 11.3上的R 2.14.1-9.1上安装rJava包.我已经看到了这个问题,但它适用于Ubuntu.我已经安装了Sun JDK并重新配置了系统以使用它.
admin@linux-nb3w:~> java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode)
admin@linux-nb3w:~>
Run Code Online (Sandbox Code Playgroud)
编辑1:
更新了JDK和JRE.现在运行时出现稍微不同的错误install.packages("rJava"),我得到以下输出错误(发布新错误,粗体以结尾):
> install.packages("rJava")
Installing package(s) into ‘/home/admin/R/i686-pc-linux-gnu-library/2.14’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
trying URL 'http://ftp.iitm.ac.in/cran/src/contrib/rJava_0.9-3.tar.gz'
Content type 'application/x-gzip' length 537153 bytes (524 Kb)
opened URL
==================================================
downloaded 524 …Run Code Online (Sandbox Code Playgroud) 我的 R Studio 版本是 4.0。我安装了 xlsx 包,但是当我需要使用它时,出现错误:
library(xlsx)
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
Error: package or namespace load failed for ‘xlsx’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JVM could not be found
In addition: Warning messages:
1: In system("/usr/libexec/java_home", intern = TRUE) :
running command '/usr/libexec/java_home' had status 1
2: In fun(libname, pkgname) :
Cannot find JVM library 'NA/lib/server/libjvm.dylib'
Install Java and/or check JAVA_HOME …Run Code Online (Sandbox Code Playgroud) 无法在ubuntu中安装rjava包,R版本为3.1.jdk i.7已安装.请分享R的java配置的确切路径.我已经尝试过javareconf -e来设置rjava的env.
以下是rJava安装后的输出.
install.packages("rJava")
Installing package into ‘/home/emraan/R/i686-pc-linux-gnu-library/3.1’
* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -std=gnu99
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 gcc -std=gnu99 accepts -g... …Run Code Online (Sandbox Code Playgroud)