From morkus at protonmail.com  Thu Oct 26 19:23:29 2017
From: morkus at protonmail.com (Morkus)
Date: Thu, 26 Oct 2017 13:23:29 -0400
Subject: [Rd] How to create a table structure in Java code?
In-Reply-To: <Ksi_rtmM5hkCpUFlhDo4eXzs-MvAN4wMgz9ZLGPoV4dituINMXOa_E-0_wJVthIx0-x8vqfJNEk7Z2pRfz3BgvfRtmog47mcuWUnTcCp_YE=@protonmail.com>
References: <TNxOU9bI1Nh3erxhoQT01mOAwutGoyscR-w7sumoj2hZY0fkKbVCK1Vl-Fwd_Vs-2NQjDQyRLNixrYz-8HA6X-tZZ-ltlk0mpWWp4QD6Q90=@protonmail.com>
 <7f1e36fe-f2c4-dce7-bb20-5c8a74f3f630@eoos.dds.nl>
 <qsAgsMs7JEnlkk9L-qi3GdtzAHk_Pom_FEfjfV2xGOm4iQxPYvapzPzUBAPyc5paAADkx0-sv16KwxJC-djTdd_MPvUCJcIbnh2yeljlB_8=@protonmail.com>
 <F66F7C74-DFB6-4986-A240-12255D0C7B44@R-project.org>
 <Ksi_rtmM5hkCpUFlhDo4eXzs-MvAN4wMgz9ZLGPoV4dituINMXOa_E-0_wJVthIx0-x8vqfJNEk7Z2pRfz3BgvfRtmog47mcuWUnTcCp_YE=@protonmail.com>
Message-ID: <OnDwVp2Xn_f57tNAza2EdA7KaxcMcDBge4UsMgZVnn0rme5rsMeKUfT5DnmXZ2VHq440UJzt0Y62vKe1QZEoOD_Yc_Hx8F2zJi4SPvQgc54=@protonmail.com>

ALMOST THERE!!!!

I have one small remaining problem.

Now that I can read in the CSV data, thanks again for that help, I create a data frame from all the REXPDouble and the one REXPString object and I'm then trying to do a boxM (Box's M) test.

The documentation says that a data frame should work with boxM so maybe I'm back in "quote hell"?

I've tried the "problem command" (two lines below) both with putting the entire boxM command inside the quotes and having the "myDf" be outside the quotes.

The line of code below that still throws a parse error is:

REXP boxMResult = rConnection.parseAndEval( "boxM(" + myDf+ "[,-5], " + myDf + " [, 5])");

Thanks again to all...this is an incredible forum!!!

I offer a virtual beer to whomever helps! :)

----

ENTIRE CODE SNIPPET:

rConnection.eval("library('biotools')");

String inputIris = "5.1,3.5,1.4,0.2,setosa\n" +
"4.9,3,1.4,0.2,setosa\n" +
"5.5,2.4,3.7,1,versicolor\n" +
"5.8,2.7,3.9,1.2,versicolor\n" +
"6,2.7,5.1,1.6,versicolor\n" +
"7.9,3.8,6.4,2,virginica\n" +
"6.4,2.8,5.6,2.2,virginica\n" +
"6.3,2.8,5.1,1.5,virginica\n" +
"6.1,2.6,5.6,1.4,virginica";

(some IRIS data removed above for brevity.)

List tableRead = rConnection.eval(
"read.csv(textConnection(\"" + inputIris + "\"), header = FALSE)").asList();    // Yes works!!!

double[] d1 = ((REXPVector) ((RList) tableRead).get(0)).asDoubles();
double[] d2 = ((REXPVector) ((RList) tableRead).get(1)).asDoubles();
double[] d3 = ((REXPVector) ((RList) tableRead).get(2)).asDoubles();
double[] d4 = ((REXPVector) ((RList) tableRead).get(3)).asDoubles();
int[] d5 = ((REXPFactor) ((RList) tableRead).get(4)).asIntegers() ;

// create data frame with data extracted from tableRead List object.REXP myDf = REXP.createDataFrame(new RList(
new REXP[]
{
new REXPDouble(d1),
new REXPDouble(d2),
new REXPDouble(d3),
new REXPDouble(d4),
new REXPInteger(d5)
}));

>>>> ERROR HERE >>>> REXP boxMResult = rConnection.parseAndEval( "boxM(" + myDf+ "[,-5], " + myDf + " [, 5])");

eval failed, request status: R parser: syntax error
org.rosuda.REngine.REngineException: eval failed, request status: R parser: syntax error
	[[alternative HTML version deleted]]



[Rd] How to create a table structure in Java code?
Morkus