Open GoogleCodeExporter opened 8 years ago
Solved.
Original comment by mhsatman
on 27 Jul 2011 at 7:27
Hello,
I just installed RCaller and got the same exact exception behavior above. What is the solution ??
Thanks!
Original comment by alejandr...@gmail.com
on 13 Sep 2011 at 5:15
can you please post your code and complete error tree?
Original comment by mhsatman
on 14 Sep 2011 at 12:26
As a user reported, after installing the package Runiversal, he has no longer
had the same error. In R type
install.packages("Runiversal")
manually and run your class again. This package should be installed and loaded
automatically by the RCaller but it is not realized as supposed in Windows
systems.
Original comment by mhsatman
on 30 Sep 2011 at 7:06
Your suggestion solves the problem for the time being.
However, R installs packages in a temporary directory, so the problem could
resurface any time. Is there a more permanent solution on the way?
Also, may I suggest documenting this in a wiki pages, so it's more obvious to
new users?
Original comment by ursreu...@gmail.com
on 11 Oct 2011 at 10:01
It seems the Runiversal package must be installed by an external way but I will
consider your suggestion for this.
Would you want to join project for editing wiki and the code?
Original comment by mhsatman
on 11 Oct 2011 at 10:17
If you are alright with not much happening on my side once this is done, I'll
do it.
My interest in R is temporary at best, because right now, it's the easiest way
to solve a problem at work.
Just drop me a message if you decide to add me anyway.
Original comment by ursreu...@gmail.com
on 12 Oct 2011 at 9:27
import java.io.File;
import javax.swing.ImageIcon;
import rcaller.RCaller;
public class Test1 {
public static void main(String[] args) {
new Test1();
}
/*
* Test for simple plots
*/
public Test1() {
try {
RCaller caller = new RCaller();
caller.setRscriptExecutable("/usr/bin/Rscript");
caller.cleanRCode();
double[] numbers = new double[]{1, 4, 3, 5, 6, 10};
caller.addDoubleArray("x", numbers);
caller.addRCode("my.mean<-mean(x)");
caller.runAndReturnResult("my.mean");
double[] result;
result = caller.getParser().getAsDoubleArray("mean");
System.out.println("Mean is "+result[0]);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
** This is my code and getting the above error.
I had already installed Runiversal
its located in /tmp/RtmpobLsMT/downloaded_packages
Original comment by vinnida...@gmail.com
on 15 Dec 2011 at 9:08
change your code to
double[] numbers = new double[]{1, 4, 3, 5, 6, 10};
caller.addDoubleArray("x", numbers);
caller.addRCode("results<-list(mymean = mean(x))");
caller.runAndReturnResult("results");
double[] result;
result = caller.getParser().getAsDoubleArray("mymean");
Original comment by mhsatman
on 15 Dec 2011 at 9:46
Its still not working..
I am sending error and .java file.
please have a look.
thanks..
Original comment by vinnida...@gmail.com
on 15 Dec 2011 at 12:27
Attachments:
your code is ok. it should run. Please, check the path of Rscript and correct
if it is not in /usr/bin
Original comment by mhsatman
on 16 Dec 2011 at 7:18
No the path is fine..
I'd started with R installing 2.14.0 version but was unable to install
Runiversal, thus i installed r 2.13.2 version without uninstalling the previous
one
May this be a problem..
Or there may be some problem with path of Runiversal installed.
Thanks
vin
Original comment by vinnida...@gmail.com
on 17 Dec 2011 at 8:04
Solved!!
the path of Rscript that worked was in the bin dir of R installed...
and I was trying that of /usr/bin of Ubuntu...
Thanks a lot..
- vin
Original comment by vinnida...@gmail.com
on 17 Dec 2011 at 10:02
I got the same error. I'm running R on mac, and installed Runiversal already.
Here's my code:
Random random = new Random();
RCaller caller = new RCaller();
caller.setRscriptExecutable("/usr/bin/Rscript");
double[] data = new double[100];
for (int i = 0; i < data.length; i++) {
data[i] = random.nextGaussian();
}
caller.addDoubleArray("x", data);
caller.addRCode("my.model <- arima(x,order=c(1,1,1))");
caller.addRCode("my.pd <- options(digits=5)");
caller.addRCode("results<-list(pred=predict(model))");
caller.runAndReturnResult("results");
double[] results;
results = caller.getParser().getAsDoubleArray("pred");
System.out.println("prediction is " + results[0]);
Original comment by yangsun....@gmail.com
on 7 Feb 2012 at 12:02
Thank you all for sharing the issues.
I also got the same problem and the same error.
Any progress fixing. I tried to figured it inside out with
- change of path
- change of R version
Nothing worked so far...
al
Original comment by apptvieu...@gmail.com
on 24 Feb 2012 at 8:52
I got same problem. but I solved by set 'BOTH' correct RExecutable and
RscriptExecutable path.
Original comment by manmustb...@gmail.com
on 30 Mar 2012 at 5:38
I got same problem too.
..................
caller.setRscriptExecutable("C:/Program Files/R/bin/Rscript.exe");
code.addRCode("ausgangsstoff <- 200.0");
code.addRCode("k.eins <- 5");
code.addRCode("k.zwei <- 8");
code.addRCode("k.drei <- 7");
code.addRCode("zeit <- seq(,12, by=0.01)");
code.addRCode("c.drei <- rep(NA, length(zeit)");
code.addRCode("for(i in 1:length(zeit)){c.drei[i] =
ausgangsstoff*((k.zwei/(k.eins-k.zwei-k.drei))*exp(-k.eins*zeit[i])-(k.eins*k.zw
ei/((k.eins-k.zwei-k.drei)*(k.zwei*k.drei)))*exp(-1*(k.zwei+k.drei)*zeit[i])+k.z
wei/(k.zwei+k.drei))}");
code.addRCode("results<-list(test=c.drei)");
caller.setRCode(code);
caller.runAndReturnResult("results");
...............
the Rscript path is correct and i have install the lates Version of R..But what
is the problem now? can anybody help?
Original comment by Stefan.K...@gmail.com
on 2 Apr 2012 at 6:09
The way I solved it: (I'm using 64 bit version of R), so in the code I just
changed the line:
caller.setRscriptExecutable("C:/Program Files/R/R-2.15.0/bin/Rscript");
to the following line:
caller.setRscriptExecutable("C:/Program Files/R/R-2.15.0/bin/x64/Rscript");
(please note that I'm using RCaller-2.0.7.jar as source). it's attached
Original comment by ro...@anametrix.com
on 7 Apr 2012 at 1:22
i have try it with the same R version but with RCaller 2.1.0 and it doesnt work
i dont know why the sample application on the RCaller Site works but not my
example
Original comment by Stefan.K...@gmail.com
on 7 Apr 2012 at 6:42
[deleted comment]
YIPPI i found the error it works now
look here is my error
code.addRCode("c.drei <- rep(NA, length(zeit)");
one round bracket is missing correct is
code.addRCode("c.drei <- rep(NA, length(zeit))");
Original comment by Stefan.K...@gmail.com
on 8 Apr 2012 at 9:36
[deleted comment]
Hi, I have try to run the Rcaller in my java program. I got some error when i
was import r packages inside the java code using RCaller library. Please let me
know the solution to solve this problem. This is my sample code given below.
RCaller caller = new RCaller();
caller.setRscriptExecutable("/usr/local/bin/Rscript");
caller.cleanRCode();
String[] data = new String[]{"test","test1" , "test3", "test4", "test5", "test6"};
caller.addStringArray("x", data);
caller.R_require("tm");
caller.addRCode("text<-paste(x)");
caller.addRCode("cp<-Corpus(text)");
caller.runAndReturnResult("cp");
String[] result;
result = caller.getParser().getAsStringArray("cp");
System.out.println("Text is "+result[0]);
My error message is :
[Fatal Error] Routput4733190479360896857:1:1: Premature end of file.
require(tm)
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org"
}
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org"
}
x<-c("test", "test1", "test3", "test4", "test5", "test6");
my.mean<-c(x)
cp<-corpus(my.mean)
cat(makexml(obj=cp, name="cp"), file="/tmp/Routput4733190479360896857")
rcaller.exception.RCallerExecutionException: Can not handle R results due to :
rcaller.exception.RCallerParseException: Can not parse the R output:
org.xml.sax.SAXParseException: Premature end of file.
Original comment by zimbh...@gmail.com
on 12 Apr 2012 at 7:39
Copy and paste your generated r code into the r interpreter and see what is the
error with your code.
Original comment by mhsatman
on 12 Apr 2012 at 7:41
Hello,
Rcaller seems to work pretty well and I am starting to use it as I want to have
my scripts written in R and run them from Java.
I am having the exact same problem with this exception.
For a first test, I generated R code to create a pdf file and call it from
java. It is something easy, and worked fine, the pdf file was generated
properly.
Now, I want to call again one “.R file” containing a particular function
within, but the problem is always the same:
[Fatal Error] Routput4280160344587065721:1:1: Premature end of file.
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org")
}
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org")
}
cat(makexml(obj=ols, name="ols"),
file="C:/DOCUME~1/MBMONT~1/CONFIG~1/Temp/Routput8192804637477966385")
source("C:/Documents and Settings/mbmonteiro/Escritorio/Cima/Java_test.R")
q("yes")
source("C:/Documents and Settings/mbmonteiro/Escritorio/Cima/Java_test_2.R")
q("yes")
set.seed(1234)
x <- rpois(500, 4)
y <- mysummary(x)
cat(makexml(obj=y, name="y"),
file="C:/DOCUME~1/MBMONT~1/CONFIG~1/Temp/Routput4280160344587065721")
rcaller.exception.RCallerExecutionException: Can not handle R results due to :
rcaller.exception.RCallerParseException: Can not parse the R output:
org.xml.sax.SAXParseException; systemId:
file:/C:/DOCUME~1/MBMONT~1/CONFIG~1/Temp/Routput4280160344587065721;
lineNumber: 1; columnNumber: 1; Premature end of file.
I know I have the correct RScript path
caller.setRscriptExecutable("C:/Archivos de programa/R/R-2.15.0/bin/Rscript");
and that “Runiversal” is installed.
I also tested to call it from the R console source("C:/Documents and
Settings/mbmonteiro/Escritorio/Cima/Java_test_2.R") and I could use mysummary
function properly.
Could someone help me to understand how should I call a function from the file
and use its parameters from java.
CODE that is giving problems:
caller.addRCode("source(\"C:/Documents and
Settings/mbmonteiro/Escritorio/Cima/Java_test_2.R\")");
caller.runOnly();
caller.addRCode("set.seed(1234)");
caller.addRCode("x <- rpois(500, 4)");
caller.addRCode("y <- mysummary(x)");
caller.runAndReturnResult("y");
Please find the entire java code attached.
I am looking forward to hearing from you,
Mariana
Original comment by marianab...@gmail.com
on 20 Sep 2012 at 10:22
Attachments:
Hello,
Thank you for your RCaller library.
Here is my R code which is working:
> file.choose()
[1] "/Users/bendarraz/Documents/ObjTable.RData"
> file<-file.choose()
> load(file)
> seed.landslide <- sample(ObjTable$Mean.OID[(which(ObjTable$class_name ==
'landslide'))], 1)
> seed.non.landslide <- sample(ObjTable$Mean.OID[(which(ObjTable$class_name ==
'non landslide'))], 1)
> selection <- c(seed.landslide, seed.non.landslide)
> selection
[1] 56736 105804
> new.OID <- query(ObjTable, selection, n.trees=50)
> new.OID
[1] 301848
I got the same error. I'm running R on mac, and installed Runiversal already.
Here's my Java code:
caller.setRscriptExecutable("/usr/bin/Rscript");
String file = "/Users/bendarraz/Documents/ObjTable.RData";
/*
* Adding R Code
*/
code.addRCode("load(file)");
code.addRCode("seed.landslide <- sample(ObjTable$Mean.OID[(which(ObjTable$class_name == 'landslide'))], 1)");
code.addRCode("seed.non.landslide <- sample(ObjTable$Mean.OID[(which(ObjTable$class_name == 'non landslide'))], 1)");
code.addRCode("selection <- c(seed.landslide, seed.non.landslide)");
code.addRCode ("source(/Users/bendarraz/Documents/query.r)");
code.addRCode("nouveau.OID <- query(ObjTable, selection, n.trees=50)");
double[] results;
results = caller.getParser().getAsDoubleArray("nouveau.OID");
System.out.println("nouveau.OID" + results[0]);
I use both external objTable.Rdata and query.R files.
I would like to display the results but it seems that the runAndReturnResult()
and getAsDoubleArray() methods don't work in this case.
I tried several solutions found in these comments (path of Rscript, using
"list()" instead of "new.OID", installing Runiversal...) without success.
Thank you for helping.
Best regards.
Original comment by bendar...@gmail.com
on 21 Sep 2012 at 9:33
2 questions:
Is it correct to call an Rdata file like this:
code.R_source("/Users/bendarraz/Documents/ObjTable.RData");
Is it legal to write like in R a statement like this with Rcaller?
code.addRCode("seed.landslide <-
sample(ObjTable$Mean.OID[(which(ObjTable$class_name == 'landslide'))], 1)");
Thanks
Original comment by bendar...@gmail.com
on 2 Oct 2012 at 8:32
Juste a preciseness: the R_source is not indicated for Rdata files.
But my load statement doesn't work anyway:
code.addRCode("load(/Users/bendarraz/Documents/ObjTable.RData)");
Any idea about how to fix my issue?
Thank you
Original comment by bendar...@gmail.com
on 3 Oct 2012 at 8:58
Hello
I'm trying RCaller in order to execute BG-NBD analysis
I downloaded this jar "RCaller-2.1.1-SNAPSHOT.jar" and I tried to execute the R
code listed on this url: http://code.google.com/p/clv-master-thesis/. I need to
use this R code:
http://code.google.com/p/clv-master-thesis/source/browse/trunk/model-bg-nbd.R
Now I installed the Runiversal package and I tried this sample:
RCaller caller = new RCaller();
// caller.setRscriptExecutable("/usr/bin/Rscript");
caller.setRscriptExecutable("/usr/bin/Rscript");
RCode code = new RCode();
code.clear();
double[] numbers = new double[]{1, 4, 3, 5, 6, 10};
code.addDoubleArray("x", numbers);
File file = code.startPlot();
System.out.println("Plot will be saved to : " + file);
code.addRCode("plot.ts(x)");
code.endPlot();
caller.setRCode(code);
caller.runOnly();
code.showPlot(file);
All works pretty good
I wanted to adapt it to my scenario and I wrote this unit test:
//Installare R sulla macchina e poi il package RUniversal
InputStreamReader reader = new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("model-bg-nbd.R"));
BufferedReader br = new BufferedReader(reader);
String line = null;
RCaller caller = new RCaller();
//Punto allo script R (file chiamato 'R')
caller.setRscriptExecutable("/usr/bin/Rscript");
//Inizializzo tutto
caller.cleanRCode();
RCode code = new RCode();
code.clear();
int dimensione = 5;
List<String> datas = new ArrayList<String>(dimensione);
String dataFrameElement = null;
for(int i = 0; i < dimensione; i++){
if( i == 0 ){
dataFrameElement = "ID Tempo Utente Test";
}else{
dataFrameElement = Math.random()*100+" "+Math.random()*100+" "+Math.random()*100+" "+Math.random()*100;
}
datas.add(dataFrameElement);
}
code.addStringArray("data", datas.toArray(new String[datas.size()]));
while( (line = br.readLine()) != null ){
//Aggiungo solo codice che non sia un commento
if(!line.startsWith("#")){
code.addRCode(line);
}
}
String doMle = "mle<-bgEstimateParameters(data, list(r=1, alpha=2, a=1, b=2));";
code.addRCode(doMle);
caller.setRCode(code);
caller.runAndReturnResult("mle");
String[] results = caller.getParser().getAsStringArray("mle");
logger.info(results[0]);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
When I execute it I get this error:
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org")
}
data<-c("ID Tempo Utente Test", "56.38316672941737 3.9741386375765853
57.82223487749921 52.82761425632678", "44.36318489079512 71.01945017181191
77.46259908894473 0.3534156420011203", "20.681228545078902 66.41194421149585
73.24614746149979 43.37634970010023", "92.28649039744393 30.800014223302007
41.60373846010842 91.87173373444988");
bgLlh <- function(data, r, alpha, a, b) {
with (data, {
if (a<=0 | b<=0 | r<=0 | alpha<=0) return (NaN)
term1 <- ( gamma(r+x) * alpha^r ) / gamma(r)
term2 <- ( gamma(a+b) * gamma(b+x) ) / (gamma(b) * gamma(a+b+x))
term3 <- 1
term4 <- (1/(alpha + T))^(r+x)
term5 <- (a/(b+x-1)) * (1/(alpha + tx))^(r+x)
llh <- log(term1) + log(term2) + log(term3) + log(term4 + as.numeric(x>0)*term5)
f <- -sum(llh)
return (f)
})
}
bgEstimateParameters <- function(data, initValues, safeMode=FALSE) {
llhd <- function(r, alpha, a, b) {
return (bgLlh(data, r, alpha, a, b))
}
library(bbmle)
if (safeMode) {
fit <- mle2(llhd, initValues, skip.hessian=TRUE, method="Nelder-Mead")
} else {
fit <- mle2(llhd, initValues)
}
return (fit)
}
bgComputePActive <- function(data, params) {
if (class(params)[1] == "mle2") params <- as.list(coef(params))
with (c(data,params), {
term1 <- (a / (b + x - 1)) * ((alpha+T)/(alpha+tx))^(r+x)
return (1 / (1 + as.numeric(x>0)*term1))
})
}
bgPx <- function(t,x,params) {
with(params, {
term1 <- (beta(a,b+x)/beta(a,b))*(gamma(r+x)/(gamma(r)*factorial(x)))*(alpha/(alpha+t))^r*(t/(alpha+t))^x
if (x==0) {
term2 <- 0
} else {
seq <- 0:(x-1)
term2a <- (gamma(r+seq)/(gamma(r)*factorial(seq)))*(t/(alpha+t))^seq
term2 <- (beta(a+1,b+x-1)/beta(a,b))*(1-(alpha/(alpha+t))^r*sum(term2a))
}
return (term1+term2)
})
}
bgConditionalForecast <- function(data, params, t) {
if (class(params)[1] == "mle2") params <- as.list(coef(params))
with(c(data,params), {
term1 <- ((a+b+x-1)/(a-1))
term2 <- 1-((alpha+T)/(alpha+T+t))^(r+x)*h2f1(r+x,b+x,a+b+x-1,t/(alpha+T+t))
term3 <- 1 + as.numeric(x>0)*(a/(b+x-1))*((alpha+T)/(alpha+tx))^(r+x)
# TODO: 1/term3 = PActive !?
out <- term1 * term2 / term3
return (out)
})
}
mle<-bgEstimateParameters(data, list(r=1, alpha=2, a=1, b=2));
cat(makexml(obj=mle, name="mle"), file="/tmp/Routput359342344387748448")
13:30:23,228 ERROR [TestScriptingLanguagesCalling] Can not handle R results due
to : rcaller.exception.ParseException: Can not parse output: The generated file
/tmp/Routput359342344387748448 is empty
rcaller.exception.ParseException: Can not handle R results due to :
rcaller.exception.ParseException: Can not parse output: The generated file
/tmp/Routput359342344387748448 is empty
at rcaller.RCaller.runAndReturnResult(RCaller.java:412)
at it.eng.test.TestScriptingLanguagesCalling.testRCaller(TestScriptingLanguagesCalling.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I can't figure what I'm wrong.
Can you give me any tips?
Cheers,
Angelo
Original comment by angelo...@gmail.com
on 20 Nov 2012 at 12:31
Hi there...any news about the showed error?
Original comment by angelo...@gmail.com
on 21 Nov 2012 at 8:29
Hai,
I am trying to read the protein sequences from online biologiclal DB. The code works well in R. Now i want to execute R script via Java. But i got error. please help....
My Code:
import rcaller.RCaller;
import rcaller.RCode;
public class ReadSeq
{
public ReadSeq()
{
try
{
RCaller caller = new RCaller();
RCode code=new RCode();
code.clear();
caller.setRscriptExecutable("C:\\Program Files\\Option\\R-2.15.1\\bin\\RScript.exe");
code.addRCode("library(\"seqinr\")");
code.addRCode("retrieveseqs <- function(seqnames,acnucdb)");
code.addRCode("{");
code.addRCode("myseqs <- list()");
code.addRCode("require(\"seqinr\")");
code.addRCode("choosebank(acnucdb)");
code.addRCode("for (i in 1:length(seqnames))");
code.addRCode("{");
code.addRCode("seqname <- seqnames[i]");
code.addRCode("print(paste(\"Retrieving sequence\",seqname,\"...\"))");
code.addRCode("queryname <- \"query2\"");
code.addRCode("query <- paste(\"AC=\",seqname,sep=\"\")");
code.addRCode("query(`queryname`,`query`)");
code.addRCode("seq <- getSequence(query2$req[[1]])");
code.addRCode("myseqs[[i]] <- seq");
code.addRCode("}");
code.addRCode("closebank()");
code.addRCode("return(myseqs)");
code.addRCode(" }");
code.addRCode("seqnames <- c(\"ACY70669\",\"ACQ44515\",\"Q6YMS4\",\"Q58HT7\")");
code.addRCode("seqs <- retrieveseqs(seqnames,\"swissprot\")");
code.addRCode("write.fasta(seqs, seqnames, file=\"type.fasta\"");
caller.setRCode(code);
//caller.runOnly();
caller.runAndReturnResult("seqs");
// System.out.println(caller.getParser().getXMLFileAsString());
//String[] s=new String[10];
//s=
//System.out.println("hai");
//System.out.println(s[0]);
String[] v = caller.getParser().getAsStringArray("seqs");
for (int i = 0; i < v.length; i++)
{
System.out.println(v[i]);
}
}
catch (Exception e){
System.out.println(e.toString());
}
}
public static void main(String args[])
{
ReadSeq R=new ReadSeq();
}
}
Error i got:
[Fatal Error] Routput3632:1:1: Premature end of file.
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org")
}
library("seqinr")
retrieveseqs <- function(seqnames,acnucdb)
{
myseqs <- list()
require("seqinr")
choosebank(acnucdb)
for (i in 1:length(seqnames))
{
seqname <- seqnames[i]
print(paste("Retrieving sequence",seqname,"..."))
queryname <- "query2"
query <- paste("AC=",seqname,sep="")
query(`queryname`,`query`)
seq <- getSequence(query2$req[[1]])
myseqs[[i]] <- seq
}
closebank()
return(myseqs)
}
seqnames <- c("ACY70669","ACQ44515","Q6YMS4","Q58HT7")
seqs <- retrieveseqs(seqnames,"swissprot")
write.fasta(seqs, seqnames, file="type.fasta"
cat(makexml(obj=seqs, name="seqs"),
file="C:/Users/PRINCI~1/AppData/Local/Temp/Routput3632")//This file is Empty
rcaller.exception.RCallerExecutionException: Can not handle R results due to :
rcaller.exception.RCallerParseException: Can not parse the R output:
org.xml.sax.SAXParseException: Premature end of file.
Original comment by aruna23j...@gmail.com
on 9 Jan 2013 at 6:20
Please have a look at my code & error and give me a suggestion....
Thank You
Original comment by aruna23j...@gmail.com
on 10 Jan 2013 at 6:27
I googled for hours but cant find a solution Please help me....
Original comment by aruna23j...@gmail.com
on 18 Jan 2013 at 5:32
Hello,
I think that this article handle the problem of "Premature end of file". I'm
not a developper, but I think that you will understand how to solve it :
http://www.danielschneller.com/2008/01/saxparseexception-1-1-premature-end-of.ht
ml
This is not a tip for the end user but an insight to the developper (or any one
who wish to help) to resolve the problem.
Original comment by hammami....@gmail.com
on 11 Apr 2013 at 4:10
[deleted comment]
Hello,
I am writing program using RCaller 2.1.1-SNAPSHOT. Problem is when i use code
from external library it says Routput file is empty. Here is my code:
Random random = new Random();
RCaller caller = new RCaller();
RCode code = new RCode();
caller.setRscriptExecutable("C:/Program Files/R/R-2.14.2/bin/x64/Rscript.exe");
double[] data = new double[100];
for (int i = 0; i < data.length; i++) {
data[i] = random.nextGaussian();
}
code.addDoubleArray("x", data);
code.addRCode("setwd('C:/Radek/')");
code.addRCode("wd=list.files()");
code.addRCode("library(Biobase)");
//code.addRCode("targets=read.AnnotatedDataFrame('targets.txt',row.names=1,as.is=TRUE)");// WHEN I USE THIS IT CRASH
code.addRCode("my.mean<-mean(x)");
code.addRCode("my.var<-var(x)");
code.addRCode("my.sd<-sd(x)");
code.addRCode("my.min<-min(x)");
code.addRCode("my.max<-max(x)");
code.addRCode("my.standardized<-scale(x)");
code.addRCode(
"my.all<-list(mean=my.mean, variance=my.var, sd=my.sd, min=my.min, max=my.max, std=my.standardized)");
caller.setRCode(code);
caller.runAndReturnResult("wd");
String[] results;
results = caller.getParser().getAsStringArray("wd");
System.out.println("Mean is " + results[0]);
Original comment by Bartek22...@gmail.com
on 29 May 2013 at 3:02
"#31 aruna23j...@gmail.com"
I have known how to solve your problem .you have to install the "Runiversal"
Package at first.
Original comment by hkp...@gmail.com
on 8 Jul 2013 at 6:05
Hello,
I have a problem with Rcalling.
I work with R x64 3.0.1 and Netbeans 7.3.1. I read the previous issues, but it
does not work for me. The Runiversal is already installed. The Rscript path is
correct.
And the problem: "java.lang.RuntimeException: Uncompilable source code -
Erroneous sym type: rcaller.RCaller.addDoubleArray"
The code: http://paste2.org/7s22wJI3
Thanks,
Original comment by girus.da...@gmail.com
on 16 Jul 2013 at 9:15
ok, I find a the problem :S It's a litle bit frustrating. The problem in the
code.
Original comment by girus.da...@gmail.com
on 17 Jul 2013 at 11:06
[deleted comment]
please find the new documentation in site
http://stdioe.blogspot.com/2013/08/a-user-document-for-rcaller.html
Original comment by mhsatman
on 19 Aug 2013 at 6:28
Hi there
I'm having a very strange behaviour. I tried one of RCaller samples. More
exactly I tried this simple Java code:
@Test
public void test(){
try {
/*
* Creating Java's random number generator
*/
Random random = new Random();
/*
* Creating RCaller
*/
RCaller caller = new RCaller();
RCode code = new RCode();
/*
* Full path of the Rscript. Rscript is an executable file shipped with R.
* It is something like C:\\Program File\\R\\bin.... in Windows
*/
caller.setRscriptExecutable("/usr/bin/Rscript");
/*
* We are creating a random data from a normal distribution
* with zero mean and unit variance with size of 100
*/
double[] data = new double[100];
for (int i = 0; i < data.length; i++) {
data[i] = random.nextGaussian();
}
/*
* We are transferring the double array to R
*/
code.addDoubleArray("x", data);
/*
* Adding R Code
*/
code.addRCode("my.mean<-mean(x)");
code.addRCode("my.var<-var(x)");
code.addRCode("my.sd<-sd(x)");
code.addRCode("my.min<-min(x)");
code.addRCode("my.max<-max(x)");
code.addRCode("my.standardized<-scale(x)");
/*
* Combining all of them in a single list() object
*/
code.addRCode(
"my.all<-list(mean=my.mean, variance=my.var, sd=my.sd, min=my.min, max=my.max, std=my.standardized)");
/*
* We want to handle the list 'my.all'
*/
caller.setRCode(code);
caller.runAndReturnResult("my.all");
double[] results;
/*
* Retrieving the 'mean' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("mean");
System.out.println("Mean is " + results[0]);
/*
* Retrieving the 'variance' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("variance");
System.out.println("Variance is " + results[0]);
/*
* Retrieving the 'sd' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("sd");
System.out.println("Standard deviation is " + results[0]);
/*
* Retrieving the 'min' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("min");
System.out.println("Minimum is " + results[0]);
/*
* Retrieving the 'max' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("max");
System.out.println("Maximum is " + results[0]);
/*
* Retrieving the 'std' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("std");
/*
* Now we are retrieving the standardized form of vector x
*/
System.out.println("Standardized x is ");
for (int i = 0; i < results.length; i++) {
System.out.print(results[i] + ", ");
}
} catch (Exception e) {
e.printStackTrace();
}
}
On my machine (ubuntu 12.04) all works pretty good; I tried, then, on my server
machine (a RedHat machine); I tried the same code; the only difference is that
since this RedHat machien couldn't access on internet I had to install manually
R and RUniversal; after I installed them I tried this code (the same of before
but with differente RScript location):
@Test
public void test(){
try {
/*
* Creating Java's random number generator
*/
Random random = new Random();
/*
* Creating RCaller
*/
RCaller caller = new RCaller();
RCode code = new RCode();
/*
* Full path of the Rscript. Rscript is an executable file shipped with R.
* It is something like C:\\Program File\\R\\bin.... in Windows
*/
caller.setRscriptExecutable("/usr/R-2.14.1/bin/Rscript");
/*
* We are creating a random data from a normal distribution
* with zero mean and unit variance with size of 100
*/
double[] data = new double[100];
for (int i = 0; i < data.length; i++) {
data[i] = random.nextGaussian();
}
/*
* We are transferring the double array to R
*/
code.addDoubleArray("x", data);
/*
* Adding R Code
*/
code.addRCode("my.mean<-mean(x)");
code.addRCode("my.var<-var(x)");
code.addRCode("my.sd<-sd(x)");
code.addRCode("my.min<-min(x)");
code.addRCode("my.max<-max(x)");
code.addRCode("my.standardized<-scale(x)");
/*
* Combining all of them in a single list() object
*/
code.addRCode(
"my.all<-list(mean=my.mean, variance=my.var, sd=my.sd, min=my.min, max=my.max, std=my.standardized)");
/*
* We want to handle the list 'my.all'
*/
caller.setRCode(code);
caller.runAndReturnResult("my.all");
double[] results;
/*
* Retrieving the 'mean' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("mean");
System.out.println("Mean is " + results[0]);
/*
* Retrieving the 'variance' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("variance");
System.out.println("Variance is " + results[0]);
/*
* Retrieving the 'sd' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("sd");
System.out.println("Standard deviation is " + results[0]);
/*
* Retrieving the 'min' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("min");
System.out.println("Minimum is " + results[0]);
/*
* Retrieving the 'max' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("max");
System.out.println("Maximum is " + results[0]);
/*
* Retrieving the 'std' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("std");
/*
* Now we are retrieving the standardized form of vector x
*/
System.out.println("Standardized x is ");
for (int i = 0; i < results.length; i++) {
System.out.print(results[i] + ", ");
}
} catch (Exception e) {
e.printStackTrace();
}
}
The result is this error (the full log is attached to the comment):
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org")
}
x<-c(0.9460408936904934, -0.5551529340765661, -0.35445834679546645,
-1.51636590395837, 2.2956289121860416, 0.7961003175829097, -0.553206999727886,
2.315240334505462, -0.017115179285881, 0.6184951794447279, 0.6915152380610504,
-1.7002491464823233, 0.6264562094568216, -1.1559911633306237,
0.36967000660952554, 1.963700830941016, 0.9948380757605925,
-1.1440168002233462, 0.7686385077566624, 0.4260438110910772,
-1.0140412741048628, -0.36865279696692693, 0.5610950844352786,
0.28561328328451924, 0.9726717376491374, 0.029346372842546632,
0.4137343107224211, 0.48776207142308714, 0.9321365198870694,
-1.6059931811975339, 0.10383129977895356, 0.5000234810742558,
-0.9307116155449479, 0.23947794756472315, -0.5334831970109568,
-0.7343565984781026, 0.8307302650200427, -0.8336411751220243,
0.2303754210890316, 1.0183478980941134, -1.4274204697242634,
1.9508730713014155, 0.7877908761802193, 0.32647375169584586,
-1.2600650564760432, 0.24719441363979894, 1.6519367759561165,
0.19944952688290857, -0.016926808693460468, 2.5535079470367803,
-1.1329244716942193, 0.1475209963081771, 1.1695222619885026,
1.6240089994594509, -1.6212519976525093, -0.8559766273780655,
-1.5891682505694165, 1.522183605412435, -0.5295164167509316,
0.9842694632961287, 0.934383962317939, 0.6383625582695062,
-0.005497226459792411, 0.19072525124366085, 0.014204872493350165,
0.2722833105208218, -1.9043009664640396, 1.5785479645639267,
0.5038222038212852, 0.8309506251239861, 1.5125093320129204,
-1.7859379204123993, 0.2975875921160099, -0.479145400721361,
-0.038933950814963265, 0.6740939785314669, 0.4616697866959242,
0.07347724181759564, 0.012080002279981822, 1.5181164033923689,
0.7255854119790351, 0.07480164480677463, 0.19357551184884908,
0.38118600240068296, -0.6064523197000228, 1.6168512382147002,
-0.21080943922429346, 0.6489816305321042, 1.0477859123379218,
-0.5368095480475188, 0.8858732100717299, -1.3513565717588267,
-0.0017381349589358603, -1.6175074638240021, 1.6136046244199642,
0.18818103099731928, 3.0417995806180325, 1.0290236224860667,
-1.0577298998024147, -0.9160535295724807);
my.mean<-mean(x)
my.var<-var(x)
my.sd<-sd(x)
my.min<-min(x)
my.max<-max(x)
my.standardized<-scale(x)
my.all<-list(mean=my.mean, variance=my.var, sd=my.sd, min=my.min, max=my.max,
std=my.standardized)
cat(makexml(obj=my.all, name="my.all"), file="/tmp/Routput8052211084061009874")
rcaller.exception.ParseException: Can not handle R results due to :
rcaller.exception.ParseException: Can not parse output: The generated file
/tmp/Routput8052211084061009874 is empty
And effectively, the XML file was empty. Since I was thinking that it was
related to my manual installation of R, I tried the this R code in the R shell:
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org")
}
x<-c(0.9460408936904934, -0.5551529340765661, -0.35445834679546645,
-1.51636590395837, 2.2956289121860416, 0.7961003175829097, -0.553206999727886,
2.315240334505462, -0.017115179285881, 0.6184951794447279, 0.6915152380610504,
-1.7002491464823233, 0.6264562094568216, -1.1559911633306237,
0.36967000660952554, 1.963700830941016, 0.9948380757605925,
-1.1440168002233462, 0.7686385077566624, 0.4260438110910772,
-1.0140412741048628, -0.36865279696692693, 0.5610950844352786,
0.28561328328451924, 0.9726717376491374, 0.029346372842546632,
0.4137343107224211, 0.48776207142308714, 0.9321365198870694,
-1.6059931811975339, 0.10383129977895356, 0.5000234810742558,
-0.9307116155449479, 0.23947794756472315, -0.5334831970109568,
-0.7343565984781026, 0.8307302650200427, -0.8336411751220243,
0.2303754210890316, 1.0183478980941134, -1.4274204697242634,
1.9508730713014155, 0.7877908761802193, 0.32647375169584586,
-1.2600650564760432, 0.24719441363979894, 1.6519367759561165,
0.19944952688290857, -0.016926808693460468, 2.5535079470367803,
-1.1329244716942193, 0.1475209963081771, 1.1695222619885026,
1.6240089994594509, -1.6212519976525093, -0.8559766273780655,
-1.5891682505694165, 1.522183605412435, -0.5295164167509316,
0.9842694632961287, 0.934383962317939, 0.6383625582695062,
-0.005497226459792411, 0.19072525124366085, 0.014204872493350165,
0.2722833105208218, -1.9043009664640396, 1.5785479645639267,
0.5038222038212852, 0.8309506251239861, 1.5125093320129204,
-1.7859379204123993, 0.2975875921160099, -0.479145400721361,
-0.038933950814963265, 0.6740939785314669, 0.4616697866959242,
0.07347724181759564, 0.012080002279981822, 1.5181164033923689,
0.7255854119790351, 0.07480164480677463, 0.19357551184884908,
0.38118600240068296, -0.6064523197000228, 1.6168512382147002,
-0.21080943922429346, 0.6489816305321042, 1.0477859123379218,
-0.5368095480475188, 0.8858732100717299, -1.3513565717588267,
-0.0017381349589358603, -1.6175074638240021, 1.6136046244199642,
0.18818103099731928, 3.0417995806180325, 1.0290236224860667,
-1.0577298998024147, -0.9160535295724807);
my.mean<-mean(x)
my.var<-var(x)
my.sd<-sd(x)
my.min<-min(x)
my.max<-max(x)
my.standardized<-scale(x)
my.all<-list(mean=my.mean, variance=my.var, sd=my.sd, min=my.min, max=my.max,
std=my.standardized)
cat(makexml(obj=my.all, name="my.all"), file="/tmp/Routput8052211084061009874")
By executing it in the R shell, all works pretty good and I can find the file
Routput8052211084061009874.xml filled and not empty
Do you have any suggestion? How can I solve this issue?
Thank you,
Angelo
Original comment by angelo...@gmail.com
on 6 Sep 2013 at 9:33
Hi there
By debugging on my RedHat machine I saw a strange thing; I just put some prints
in the class "rcaller.RStreamHandler"; exactly I put this system.out.println
both on my ubuntu machine and on my redhat machine:
public void run() {
if (reader == null) {
reader = new BufferedReader(new InputStreamReader(stream));
}
System.out.println("closeSignal "+closeSignal);
String s;
while (!closeSignal) {
try {
s = reader.readLine();
System.out.println("S pari a "+s);
if (s != null) {
for (EventHandler eventHandler : eventHandlers) {
eventHandler.messageReceived(name, s);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Now in my ubuntu machine I got this prints:
closeSignal false
closeSignal false
S pari a Carico il pacchetto richiesto: Runiversal
S pari a null
S pari a null
S pari a null
S pari a null
..
..
On my RedHat machine I got this prints:
closeSignal false
closeSignal false
S pari a Carico il pacchetto richiesto: Runiversal
S pari a Warning message:
S pari a In library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE, :
S pari a there is no package called ‘Runiversal’
S pari a Warning: unable to access index for repository
http://cran.r-project.org/src/contrib
S pari a null
S pari a null
S pari a null
As we can see it seems it's not able in finding the Runiversal package and it
tryes to go on internet in order to download it but unsuccessfully; the strange
thing is that in my R console, always on my redhat machine, I have this result:
> packageExist<-require(Runiversal)
> print(packageExist);
[1] TRUE
So what I'm wondering....why from Java it seems that the RUniversal package is
not installed while from R console it seems to be installed? Do you have any
suggestion?
Thank you a lot
Angelo
Original comment by angelo...@gmail.com
on 6 Sep 2013 at 10:38
Hi there :) I'm really sorry for the spamming
Now it seems to be working also on the RedHat machine; I don't know exactly why
but I simply removed and manually installed again the Runiversal package by
typing this instruction in the R console
install.packages('/${rUniversalHome}/Runiversal_1.0.2.tar.gz', repos = NULL,
type="source")
Angelo
Original comment by angelo...@gmail.com
on 6 Sep 2013 at 11:12
Hi.... i have the same issue... it works fine when i use addRCode... but when i
try to us R_source, or addRCode("source(....)") i get the same error:
rcaller.exception.RCallerParseException: Can not parse the R output:
org.xml.sax.SAXParseException
I have installed Runiversal, it is loaden when R starts, i have the correct
path to the Rscript
Original comment by enscant...@gmail.com
on 9 Apr 2014 at 4:45
RCaller 2.2.0 is introduced in page
http://stdioe.blogspot.com.tr/2014/04/rcaller-220-is-released.html. The new
version does not depend on the R package Runiversal.
So the library is more independent, but the logic is same, R XML routines are
copied in each session. This process seems to be faster compared to R's package
loading routines.
Original comment by mhsatman
on 12 Apr 2014 at 8:28
I am trying to pass the list from Java to R but I am unable to do that due to
this issue......Please help me guys
[Fatal Error] Routput8380818569065806843:1:1: Premature end of file.
packageExist<-require(Runiversal)
if(!packageExist){
install.packages("Runiversal", repos=" http://cran.r-project.org")
}
install.packages("Runiversal")
install.packages("rJava")
plot.new()
v1<-read.csv("D:\eclipse-jee-kepler-SR2-win32-x86_64\hospital-data.xlsx")
cat(makexml(obj=boxplot(v1), name="boxplot(v1)"),
file="C:/Users/GOURAV~1/AppData/Local/Temp/Routput8380818569065806843")
rcaller.exception.RCallerExecutionException: Can not handle R results due to :
rcaller.exception.RCallerParseException: Can not parse the R output:
org.xml.sax.SAXParseException; systemId:
file:/C:/Users/GOURAV~1/AppData/Local/Temp/Routput8380818569065806843;
lineNumber: 1; columnNumber: 1; Premature end of file.
at rcaller.RCaller.runAndReturnResult(RCaller.java:402)
at com.web.controller.RHandler.rProcess(RHandler.java:41)
at com.web.controller.ExcelReader.processUploadedFile(ExcelReader.java:127)
at com.web.controller.ExcelReader.doPost(ExcelReader.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
Script executed
Original comment by gouravso...@gmail.com
on 2 Oct 2014 at 7:04
Attachments:
gouravsonu89 you are using an old version. please try the latest one.
Original comment by mhsatman
on 2 Oct 2014 at 8:24
Hi,
I am using R-3.1.1 in my window 8 can you please send me the latest version
link..
with regards,
Gourav Khare
Original comment by gouravso...@gmail.com
on 2 Oct 2014 at 8:52
gouravsonu89 use the latest version of rcaller.
visit the page http://mhsatman.com/rcaller/
Original comment by mhsatman
on 2 Oct 2014 at 11:00
Original issue reported on code.google.com by
mhsatman
on 22 Jul 2011 at 8:10