From rhelp at eoos.dds.nl  Thu Oct 26 13:45:06 2017
From: rhelp at eoos.dds.nl (Jan van der Laan)
Date: Thu, 26 Oct 2017 13:45:06 +0200
Subject: [Rd] How to create a table structure in Java code?
In-Reply-To: <TNxOU9bI1Nh3erxhoQT01mOAwutGoyscR-w7sumoj2hZY0fkKbVCK1Vl-Fwd_Vs-2NQjDQyRLNixrYz-8HA6X-tZZ-ltlk0mpWWp4QD6Q90=@protonmail.com>
References: <TNxOU9bI1Nh3erxhoQT01mOAwutGoyscR-w7sumoj2hZY0fkKbVCK1Vl-Fwd_Vs-2NQjDQyRLNixrYz-8HA6X-tZZ-ltlk0mpWWp4QD6Q90=@protonmail.com>
Message-ID: <7f1e36fe-f2c4-dce7-bb20-5c8a74f3f630@eoos.dds.nl>


I suspect that you are looking for something like:

read.csv(textConnection(
"5.1,3.5,1.4,0.2,setosa
4.9,3,1.4,0.2,setosa
4.7,3.2,1.3,0.2,setosa
4.6,3.1,1.5,0.2,setosa
5,3.6,1.4,0.2,setosa"
), header = FALSE)

HTH,
Jan



On 25-10-17 12:50, Morkus via R-devel wrote:
> Hi all,
> 
> Using RConsole, it's easy to get data from the database that you can use in an R Command. Like this:
> 
> (Reference case)
> 
> irisQuery <- dbGetQuery(conn, "select * from iris")
> boxM(irisQuery [,-5], irisQuery[,5])
> 
> ----
> 
> (Actual case this posting is about)
> 
> Yet, if I'm getting that same (sample IRIS) data, say, in a web service possibly POSTED from a SQL command, that same data might look like this (portion of the included iris data set below). I'm thus not sure how to package the data so R likes it.
> 
> Example R-included IRIS data from SQL output:
> 
> 5.1,3.5,1.4,0.2,setosa,
> 4.9,3,1.4,0.2,setosa,
> 4.7,3.2,1.3,0.2,setosa,
> 4.6,3.1,1.5,0.2,setosa,
> 5,3.6,1.4,0.2,setosa,
> 
> I've tried various combinations in code to achieve what's simple in RConsole, but I can't get R to accept my structure.
> 
> - I've tried just including the data in a string.
> - I've tried wrapping the data with "data"
> - I've tried wrapping the data with "data.frame" (as below).
> 
> Here's my latest attempt:
> 
> String tableRead = "data.frame(5.1,3.5,1.4,0.2,setosa\n" +
> "4.9,3,1.4,0.2,setosa\n" +
> "4.7,3.2,1.3,0.2,setosa\n" +
> "4.6,3.1,1.5,0.2,setosa\n" +
> "5,3.6,1.4,0.2,setosa)" ;
> 
> // using parseAndEval below to give me actual error R is sending...
> REXP rResponseObject = rConnection.parseAndEval("try(eval("+tableRead+"),silent=TRUE)");
> if (rResponseObject.inherits("try-error"))
> {
>       System.out.println("R Serve Eval Exception : "+rResponseObject.asString());
> }
> REXP boxMResult = rConnection.eval("boxM("+ tableRead+ "[,-5]," + tableRead + "[, 5])");  // FAILS <<
> 
> ----
> 
> Error in the above case is:
> 
> Disconnected from the target VM, address: '127.0.0.1:51356', transport: 'socket'
> org.rosuda.REngine.REngineException: eval failed, request status: R parser: syntax error
> at org.rosuda.REngine.Rserve.RConnection.parseAndEval(RConnection.java:454)
> at org.rosuda.REngine.REngine.parseAndEval(REngine.java:108)
> at net.example.start_r_fromjava.RStatisticsExample.main(RStatisticsExample.java:151)
> 
> Does the POSTed data need to be in a different format or am I just not framing it correctly?
> 
> Would appreciate any tips on how to package table data that might come from a SQL Query passed to Java code.
> 
> Thanks very much in advance,
> 
> - M
> 
> Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] How to create a table structure in Java code?
Jan van der Laan