Hello,
I want to import R-output via Rserve to Java, especially for the function
ctree from the package party.
Rserve is working properly.
Yet, I only get the predictions with the Java code
try{
RConnection c = new RConnection();
...
c.voidEval("modell <- ctree(...)");
REXP y = c.eval("nodes(modell,1)[[1]]$prediction");
...
}catch(Exception e){}
When I try to get the whole text with
REXP z = c.eval("nodes(modell,1)[[1]]");
System.out.println(z);
I get something like
org.rosuda.REngine.REXPGenericVector at 119c082+[10]named
But I want the text which is printed in R.
What can I do?
Thanks, Max
Once again:
It`s clear to get the result in R but I don`t know hoe to get the R-output
into Java (or into a file, i.e. .txt)
--
View this message in context:
http://www.nabble.com/Import-R-output-into-Java-tp22601443p22601443.html
Sent from the R help mailing list archive at Nabble.com.
Maxl18 wrote:> Hello, > I want to import R-output via Rserve to Java, especially for the function > ctree from the package party. > Rserve is working properly. > > Yet, I only get the predictions with the Java code > > try{ > RConnection c = new RConnection(); > ... > c.voidEval("modell <- ctree(...)"); > REXP y = c.eval("nodes(modell,1)[[1]]$prediction"); > ... > }catch(Exception e){} > > When I try to get the whole text with > > REXP z = c.eval("nodes(modell,1)[[1]]"); > System.out.println(z); > > I get something like > org.rosuda.REngine.REXPGenericVector at 119c082+[10]named > > But I want the text which is printed in R. > > What can I do? > Thanks, Max > > > Once again: > It`s clear to get the result in R but I don`t know hoe to get the R-output > into Java (or into a file, i.e. .txt) >This is what the toString method from REXP returns, you need use other REXP methods to extract what you are looking for: http://rforge.net/Rserve/doc/org/rosuda/REngine/REXP.html#asStrings() Romain -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr
#I used sink ?sink #Thomas Maxl18 schrieb:> Hello, > I want to import R-output via Rserve to Java, especially for the function > ctree from the package party. > Rserve is working properly. > > Yet, I only get the predictions with the Java code > > try{ > RConnection c = new RConnection(); > ... > c.voidEval("modell <- ctree(...)"); > REXP y = c.eval("nodes(modell,1)[[1]]$prediction"); > ... > }catch(Exception e){} > > When I try to get the whole text with > > REXP z = c.eval("nodes(modell,1)[[1]]"); > System.out.println(z); > > I get something like > org.rosuda.REngine.REXPGenericVector at 119c082+[10]named > > But I want the text which is printed in R. > > What can I do? > Thanks, Max > > > Once again: > It`s clear to get the result in R but I don`t know hoe to get the R-output > into Java (or into a file, i.e. .txt) >
Thanks, sink was exactly the function I searched.
It properly works in R, but when I try to launch it from Java, the file is
created but never written any output...
con.voidEval("test.txt"); // file is created
con.voidEval("1+1"); // nothing is written into the file
con.voidEval("sink()");
Where is my mistake?
Cheers, Max
Thomas Roth (geb. Kaliwe) wrote:>
> #I used sink
> ?sink
>
>
> #Thomas
>
>
>
> Maxl18 schrieb:
>> Hello,
>> I want to import R-output via Rserve to Java, especially for the
function
>> ctree from the package party.
>> Rserve is working properly.
>>
>> Yet, I only get the predictions with the Java code
>>
>> try{
>> RConnection c = new RConnection();
>> ...
>> c.voidEval("modell <- ctree(...)");
>> REXP y = c.eval("nodes(modell,1)[[1]]$prediction");
>> ...
>> }catch(Exception e){}
>>
>> When I try to get the whole text with
>>
>> REXP z = c.eval("nodes(modell,1)[[1]]");
>> System.out.println(z);
>>
>> I get something like
>> org.rosuda.REngine.REXPGenericVector at 119c082+[10]named
>>
>> But I want the text which is printed in R.
>>
>> What can I do?
>> Thanks, Max
>>
>>
>> Once again:
>> It`s clear to get the result in R but I don`t know hoe to get the
>> R-output
>> into Java (or into a file, i.e. .txt)
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
View this message in context:
http://www.nabble.com/Import-R-output-into-Java-tp22601443p22616132.html
Sent from the R help mailing list archive at Nabble.com.
Hi,
try this instead:
con.voidEval("sink(test.txt)");
con.voidEval("cat(1+1)");
con.voidEval("sink()");
Romain
Maxl18 wrote:> Thanks, sink was exactly the function I searched.
> It properly works in R, but when I try to launch it from Java, the file is
> created but never written any output...
>
> con.voidEval("test.txt"); // file is created
> con.voidEval("1+1"); // nothing is written into the file
> con.voidEval("sink()");
>
> Where is my mistake?
> Cheers, Max
>
>
>
>
>
> Thomas Roth (geb. Kaliwe) wrote:
>
>> #I used sink
>> ?sink
>>
>>
>> #Thomas
>>
>>
>>
>> Maxl18 schrieb:
>>
>>> Hello,
>>> I want to import R-output via Rserve to Java, especially for the
function
>>> ctree from the package party.
>>> Rserve is working properly.
>>>
>>> Yet, I only get the predictions with the Java code
>>>
>>> try{
>>> RConnection c = new RConnection();
>>> ...
>>> c.voidEval("modell <- ctree(...)");
>>> REXP y =
c.eval("nodes(modell,1)[[1]]$prediction");
>>> ...
>>> }catch(Exception e){}
>>>
>>> When I try to get the whole text with
>>>
>>> REXP z = c.eval("nodes(modell,1)[[1]]");
>>> System.out.println(z);
>>>
>>> I get something like
>>> org.rosuda.REngine.REXPGenericVector at 119c082+[10]named
>>>
>>> But I want the text which is printed in R.
>>>
>>> What can I do?
>>> Thanks, Max
>>>
>>>
>>> Once again:
>>> It`s clear to get the result in R but I don`t know hoe to get the
>>> R-output
>>> into Java (or into a file, i.e. .txt)
>>>
--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr