我已经为R构建了一个包,它将R包装在一些Java类中.在我的开发笔记本电脑(Ubuntu)上,这个软件包加载正常,效果很好.在另外两台机器(一台Ubuntu,一台Debian)上,我试图使用这个包,并且.jpackage()调用没有设置类路径.
所有三台机器都运行R 2.12.1和rJava .8-8,我认为这是最新的.
整个软件包都在谷歌代码上,但这里是zzz.R文件的内容,它用于在一台机器上设置类路径,但不在其他机器上设置类路径:
##' @import rJava
.onLoad <- function(lib, pkg) {
pathToSdk <- paste(system.file(package = "GSRadR") , "/gsrad_sample/lib/", sep="")
jarPaths <- c(paste(pathToSdk, "clima_core-1.0.0.jar", sep=""),
paste(pathToSdk, "clima_GSRAD-1.0.0.jar", sep=""),
paste(pathToSdk, "colt-1.0.jar", sep=""),
paste(pathToSdk, "commons-lang-2.0.jar", sep=""),
paste(pathToSdk, "junit-3.8.1.jar", sep=""),
paste(pathToSdk, "log4j-1.2.8.jar", sep=""),
paste(pathToSdk, "xqore.jar", sep="")
)
.jpackage(pkg, morePaths=jarPaths)
attach( javaImport( c("java.lang", "java.io")))
packageStartupMessage( paste( "GSRadR loaded. The classpath is: ", paste(.jclassPath(), collapse=" " ) ) )
}
Run Code Online (Sandbox Code Playgroud)
在我的笔记本电脑上返回以下内容:
> require(GSRadR)
Loading required package: GSRadR
Loading required package: …Run Code Online (Sandbox Code Playgroud) 我在不同的目录中有一组csv文件,我想将它们全部放在一个excel文件中,每个表放在一个excel表中.
我正在使用R和xlsx包.
# loading the library
library(xlsx)
rm(list = ls())
# getting the path of all reports (they are in csv format)
restab = system("ls /home/ubuntu/ibasruns/control/*/report",intern = TRUE)
# creating work book
wb <- createWorkbook()
# going through each csv file
for (item in restab)
{
# making each as a sheet
sheet <- createSheet(wb, sheetName=strsplit(item,"/")[[1]][6])
addDataFrame(read.csv(item), sheet)
# saving the workbook
saveWorkbook(wb, "AliceResultSummary.xlsx")
}
# finally writing it.
write.xlsx(wb, "AliceResultSummary.xlsx")
Run Code Online (Sandbox Code Playgroud)
但是,在最后一行中,我收到以下错误,
as.data.frame.default(x [[i]],optional = TRUE)中的错误:无法将类"structure("jobjRef",package ="rJava")强制转换为data.frame
我有什么遗失的东西吗?
使用install.packages("rJava")我安装rJava时会出现几个错误.
lm-mb:~ lisa$ R
R Under development (unstable) (2013-11-21 r64282) -- "Unsuffered Consequences"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin10.8.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to …Run Code Online (Sandbox Code Playgroud) 我正在尝试从R创建一个新的excel工作簿,以使用xlsx包保存一些小数据集.由于某种原因,它工作正常,但我不能再做了.
用于创建新工作簿的代码
library("xlsx")
library("xlsxjars")
library("rJava")
file <- "marca_imei.xlsx"
wb <- loadWorkbook(file)
# The error:
# Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
# java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
Run Code Online (Sandbox Code Playgroud)
我搜索了一个答案,但是从excel导入数据时似乎有人犯了同样的错误.我尝试过推荐但不起作用.以下是未来搜索者的一些链接:
sessionInfo():
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 LC_MONETARY=Spanish_Spain.1252
[4] LC_NUMERIC=C LC_TIME=Spanish_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xlsx_0.5.5 xlsxjars_0.6.0 RJDBC_0.2-3 rJava_0.9-6
[5] DBI_0.2-7 slidifyLibraries_0.3.1 slidify_0.4 knitr_1.5
[9] devtools_1.4.1 scales_0.2.3 ggplot2_0.9.3.1 data.table_1.8.11
[13] reshape2_1.2.2
loaded …Run Code Online (Sandbox Code Playgroud) 我已经制作了一个使用的包XLConnect.我可以在这里正确安装它.但是,当我尝试将它安装在别人的电脑上时,我收到了一个.onLoad failed错误.起初我也得到了.onload Failed错误library('rJava'),但是在安装64位版本的Java之后,libraray(rJava)现在可以正常工作了.但是,在尝试安装我的软件包时,我仍然会遇到相同的加载错误:
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dirname(this$RuntimeLib)
error: a character vector argument expected
Error : package 'XLConnect' could not be loaded
Error: loading failed
Execution halted
*** arch - x64
Run Code Online (Sandbox Code Playgroud)
既library(XLConnect)和library(rJava)工作.还有其他可能导致这些类型错误的东西吗?
我正在尝试测试使用mailR包从R发送电子邮件,但我不断收到我不明白的错误消息.我浏览了是否有任何现有的解决方案,但未能找到解决方案.
我还测试了使用port = 25到telnet运行相同的smtp主机,并且通过telnet连接到smtp服务器看起来很好.因此,端口和smtp主机似乎不是问题.当我因某种原因跑到R时,它只会成为一个问题.有人可以帮助解释这里的错误吗?非常感谢.
命令:
send.mail(from = "abc@company.com",
to = "xyz@company.com",
subject = "Hello this is a testing message",
body = "And this is a body text",
smtp = list(host.name = "mailhub.company.com",port=25),
authenticate = FALSE,
send = TRUE,debug=TRUE)
Run Code Online (Sandbox Code Playgroud)
错误:
DEBUG: JavaMail version 1.5.2
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: …Run Code Online (Sandbox Code Playgroud) 我在MRO 3.3.1平台中安装rJava软件包时遇到问题:平台:x86_64-pc-linux-gnu(Ubuntu 16.04LTS 64位)(以下错误消息)。
在报告了其他几个问题之后,我安装了java-8-openjdk-*,java-8-oracle,liblzma-dev等。我也尝试通过“ conda install”安装rJava,但它存储在/ anaconda3目录中,我不知道如何将其用于MRO。
有一些线索吗?
* 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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装rJava软件包以运行XLConnect软件包。这是我的系统详细信息;
R studio:版本1.0.153
Mac OS High Sierra版本10.13.1(17B1003)
R版本:3.4.2
jdk-9.0.1
但是,我得到以下错误:
我已经关注了以下有关该主题的主题,但它们对我不起作用:
在Mac El Capitan上安装和加载rJava时遇到问题
“升级”到OSX Yosemite后,RStudio / R中的rJava加载错误
朝正确方向的推动将不胜感激!
我正在尝试在Amazon Lightsail实例(Amazon Linux 2017.09.1)上运行的R中安装rJava包.我一直收到gcc找不到libgomp.spec的错误
我找到了/usr/lib/gcc/x86_64-amazon-linux/6.4.1/libgomp.spec的文件,我尝试设置一个符号链接,但我还没弄清楚在哪里放置符号链接,以便gcc可以找到它.例如,这似乎不起作用:
ln -s /usr/lib/gcc/x86_64-amazon-linux/6.4.1/libgomp.spec /usr/local/lib64/libgomp.spec
Run Code Online (Sandbox Code Playgroud)
有谁知道在哪里放置符号链接,所以gcc可以找到它?我不明白这个输出中可能有一个提示:
* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -m64 -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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用类型的rJava初始化HashMap,<String, Double>但不了解如何使用rJava接口完成此操作.我基本上是在找相同的
HashMap<String, Double> x = new HashMap<String, Double>();
Run Code Online (Sandbox Code Playgroud)
但是使用rJava代替.我可以很容易地生成HashMap<String, String>如下面的示例所示,但自然不能用双精度填充值(这是我想要实现的).
library(rJava)
.jinit()
# this works but gives me a <String, String> hashmap
x <- .jnew("java/util/HashMap")
.jrcall(x, "put", "a", "1")
x
#> [1] "Java-Object{{a=1}}"
# failing example of what I'd like to do
.jrcall(x, "put", "b", 2)
#> Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
#> java.lang.NoSuchMethodException: No suitable method for the given parameters
Run Code Online (Sandbox Code Playgroud)
我尝试.jcall()在以下主题的几个变体中使用组合串联:
.jcall("java/util/HashMap",
"Ljava/util/HashMap;[Ljava/lang/String;Ljava/lang/Double;",
"<init>")
#> Error in .jcall("java/util/HashMap", "Ljava/util/HashMap;
#> …Run Code Online (Sandbox Code Playgroud)