From murdoch.duncan at gmail.com  Sat Oct 28 13:31:41 2017
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Sat, 28 Oct 2017 07:31:41 -0400
Subject: [Rd] Cannot Compute Box's M (Three Days Trying...)
In-Reply-To: <rl0BFmHLQl4yweaOtoWaJJEScu0VetftcUuusTtgU1qjAdU-8pgrnohMfnzvJQZTY2jPjjraq6xgDDAlxfHHZunKbfGydZILJQ8xk4g0IWc=@protonmail.com>
References: <yNSrSEBSEthk1cJc2W6y3M50LXPWIRpFNyUtLE8yIZMb4guTLWuQi9XjWd4MHnt5vxOZAK1bO32QWqqM26bRU_XpiYnip5jDiyjKWUKIH7w=@protonmail.com>
 <3e5b4dc9-1b9a-4c63-a929-82a127856dbe@gmail.com>
 <P6V3IIqCfJ4SUFtNl9ML3Wmo2cvnL50vlzlUJdvRaAj106MjIojw5ITRt5ZQdkeOa9rnyS6HTxRgg7SUwmPY4CqGPbQFWqYEKCTr_yDVZdM=@protonmail.com>
 <abfb1feb-1da9-8c88-ceb5-98cef28ef406@gmail.com>
 <rl0BFmHLQl4yweaOtoWaJJEScu0VetftcUuusTtgU1qjAdU-8pgrnohMfnzvJQZTY2jPjjraq6xgDDAlxfHHZunKbfGydZILJQ8xk4g0IWc=@protonmail.com>
Message-ID: <ee03e49f-9c97-5e34-d12e-7623effcf062@gmail.com>

On 28/10/2017 7:12 AM, Morkus wrote:
> Thanks Duncan. Awesome ideas!
> 
> I think we're getting closer!
> 
> I tried what you suggested and got a possibly better error...
> .
> .
> .
> rConnection.assign("boxMVariable", myDf);
> 
> *String resultBV *= *"str(boxMVariable)"*; *// your suggestion.*
> 
> *RESULTING ERROR:*
> 
> *Error in format.default(nam.ob, width = max(ncn), justify = "left") :  
> invalid 'width' argument*
> 
> (No idea what this means).

That looks like an error occurring in the str() function.  I've never 
seen such a think in a regular R session, so I would guess that either 
your boxMVariable object is set up in a weird way that is confusing 
str(), or your R session in Java is messed up.

This is likely to be pretty hard to debug.  As a general strategy, I'd 
try to find out exactly what is in boxMVariable first.  Since str() 
doesn't work, try printing things like

head(boxMVariable)
class(boxMVariable)
names(boxMVariable)
ncol(boxMVariable)
nrow(boxMVariable)
typeof(boxMVariable)
for (i in 1:5)
   print(typeof(boxMVariable[[i]]))

etc.

Make sure the values match what you see in a regular R session:

 > boxMVariable <- iris
 >
 > head(boxMVariable)
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
 > class(boxMVariable)
[1] "data.frame"
 > names(boxMVariable)
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width" 
"Species"
 > ncol(boxMVariable)
[1] 5
 > nrow(boxMVariable)
[1] 150
 > typeof(boxMVariable)
[1] "list"
 > for (i in 1:5)
+   print(typeof(boxMVariable[[i]]))
[1] "double"
[1] "double"
[1] "double"
[1] "double"
[1] "integer"

> 
> For testing, I'm using the same standard IRIS dataset as the Box's M 
> documentation shows in biotools:
> 
> Examples
> 
> data(iris)
> *boxM(iris[, -5], iris[, 5])*
> 
> *-------*
> **
> Now, in the debugger, the built values of myDf are these:
> 
> *myDf* = {org.rosuda.REngine.REXPGenericVector at 562} 
> "org.rosuda.REngine.*REXPGenericVector*@17d99928+[5]?

> 
> ? payload = {org.rosuda.REngine.*RList*@566} size = 5
> ? 0 = {org.rosuda.REngine.REXPDouble at 570} 
> "org.rosuda.REngine.*REXPDouble*@6fffcba5[150]"
> ? 1 = {org.rosuda.REngine.REXPDouble at 571} 
> "org.rosuda.REngine.*REXPDouble*@34340fab[150]?
> ? 2 = {org.rosuda.REngine.REXPDouble at 572} 
> "org.rosuda.REngine.*REXPDouble*@2aafb23c[150]"
> ? 3 = {org.rosuda.REngine.REXPDouble at 573} 
> "org.rosuda.REngine.*REXPDouble*@2b80d80f[150]?
> ? 4 = {org.rosuda.REngine.REXPString at 574} 
> "org.rosuda.REngine.*REXPString*@3ab39c39[150]?
> 
> Does this help?
> 
> Please let me know what else I can try.
> 
> Thanks,
> 
> 
> Sent from ProtonMail <https://protonmail.com>, Swiss-based encrypted email.
> 
> 
>> -------- Original Message --------
>> Subject: Re: [Rd] Cannot Compute Box's M (Three Days Trying...)
>> Local Time: October 28, 2017 6:48 AM
>> UTC Time: October 28, 2017 10:48 AM
>> From: murdoch.duncan at gmail.com
>> To: Morkus <morkus at protonmail.com>
>> r-devel at r-project.org <r-devel at r-project.org>
>>
>> On 28/10/2017 6:26 AM, Morkus wrote:
>>
>>     I'm not sure what you mean. Could you please be more specific?
>>
>>     You were trying to eval an expression that you constructed in Java. I
>>     was suggesting that before you eval it, you print it.
>>     If I print the string, I get: /boxM(boxMVariable[, -5],
>>     boxMVariable[, 5])/
>>
>>     Right, that's what I was suggesting you do. Now you've fixed the
>>     syntax
>>     error, that looks okay.
>>
>>     If I'm reading these messages in the right order, your latest error is
>>
>>     Error in |[.data.frame|(boxMVariable, , -5) : undefined columns
>>     selected
>>
>>     The expression there is a funny way of printing boxMVariable[,-5]. So
>>     now you need to figure out why it thinks you've selected undefined
>>     columns. This is a little perplexing, because you're asking for all
>>     columns except column 5, and that works whether or not you have a
>>     column
>>
>> 5.
>>
>>
>>
>> So I'd guess there's something weird about boxMVariable. You should ask
>> R to print it, and to print str(boxMVariable), to make sure it's a
>> regular dataframe containing 4 numeric columns and one factor or
>> character column.
>>
>> Duncan Murdoch
>>
>>     From this code:
>>     .
>>     .
>>     .
>>     /// assign the data to a variable.
>>     /rConnection.assign("boxMVariable", myDf);
>>     /// create a string command with that variable name.
>>     /String boxVariable = "boxM(boxMVariable[, -5], boxMVariable[, 5])";
>>     /System/./out/./println/(/boxVariable/);? // print the string? Not
>>     sure
>>     what is meant.
>>     Sorry if I didn't understand your suggestion.
>>     Look forward to hearing back from you.
>>     Thanks,
>>     Sent from ProtonMail https://protonmail.com, Swiss-based encrypted
>>     email.
>>
>>         -------- Original Message --------
>>         Subject: Re: [Rd] Cannot Compute Box's M (Three Days Trying...)
>>         Local Time: October 27, 2017 6:09 PM
>>         UTC Time: October 27, 2017 10:09 PM
>>         From: murdoch.duncan at gmail.com <mailto:murdoch.duncan at gmail.com>
>>         To: Morkus morkus at protonmail.com
>>         <mailto:morkus at protonmail.com>, r-devel at r-project.org
>>         <mailto:r-devel at r-project.org>
>>         r-devel at r-project.org <mailto:r-devel at r-project.org>
>>         Just print the string you are asking to R to evaluate. It
>>         doesn't make
>>         any sense as an R expression. Fix that, and things will work.
>>         Duncan Murdoch
>>         On 27/10/2017 3:41 PM, Morkus via R-devel wrote:
>>
>>         |It can't be this hard, right? I really need a shove in the
>>         right direction here. Been spinning wheels for three days.
>>         Cannot get past the errors. I'm doing something wrong,
>>         obviously, since I can easily compute the Box's M right there
>>         in RStudio But I don't see what is wrong below with the coding
>>         equivalent. The entire code snippet is below. The code fails
>>         below on the call to the boxM statistic call. PLEASE HELP!!!
>>         Thanks in advance,
>>         ------------------------------------------------------------------------
>>         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" +
>>         "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\n" + "5.4,3.9,1.7,0.4,setosa\n" +
>>         "4.6,3.4,1.4,0.3,setosa\n" + "5,3.4,1.5,0.2,setosa\n" +
>>         "4.4,2.9,1.4,0.2,setosa\n" + "4.9,3.1,1.5,0.1,setosa\n" +
>>         "5.4,3.7,1.5,0.2,setosa\n" + "4.8,3.4,1.6,0.2,setosa\n" +
>>         "4.8,3,1.4,0.1,setosa\n" + "4.3,3,1.1,0.1,setosa\n" +
>>         "5.8,4,1.2,0.2,setosa\n" + "5.7,4.4,1.5,0.4,setosa\n" +
>>         "5.4,3.9,1.3,0.4,setosa\n" + "5.1,3.5,1.4,0.3,setosa\n" +
>>         "5.7,3.8,1.7,0.3,setosa\n" + "5.1,3.8,1.5,0.3,setosa\n" +
>>         "5.4,3.4,1.7,0.2,setosa\n" + "5.1,3.7,1.5,0.4,setosa\n" +
>>         "4.6,3.6,1,0.2,setosa\n" + "5.1,3.3,1.7,0.5,setosa\n" +
>>         "4.8,3.4,1.9,0.2,setosa\n" + "5,3,1.6,0.2,setosa\n" +
>>         "5,3.4,1.6,0.4,setosa\n" + "5.2,3.5,1.5,0.2,setosa\n" +
>>         "5.2,3.4,1.4,0.2,setosa\n" + "4.7,3.2,1.6,0.2,setosa\n" +
>>         "4.8,3.1,1.6,0.2,setosa\n" + "5.4,3.4,1.5,0.4,setosa\n" +
>>         "5.2,4.1,1.5,0.1,setosa\n" + "5.5,4.2,1.4,0.2,setosa\n" +
>>         "4.9,3.1,1.5,0.2,setosa\n" + "5,3.2,1.2,0.2,setosa\n" +
>>         "5.5,3.5,1.3,0.2,setosa\n" + "4.9,3.6,1.4,0.1,setosa\n" +
>>         "4.4,3,1.3,0.2,setosa\n" + "5.1,3.4,1.5,0.2,setosa\n" +
>>         "5,3.5,1.3,0.3,setosa\n" + "4.5,2.3,1.3,0.3,setosa\n" +
>>         "4.4,3.2,1.3,0.2,setosa\n" + "5,3.5,1.6,0.6,setosa\n" +
>>         "5.1,3.8,1.9,0.4,setosa\n" + "4.8,3,1.4,0.3,setosa\n" +
>>         "5.1,3.8,1.6,0.2,setosa\n" + "4.6,3.2,1.4,0.2,setosa\n" +
>>         "5.3,3.7,1.5,0.2,setosa\n" + "5,3.3,1.4,0.2,setosa\n" +
>>         "7,3.2,4.7,1.4,versicolor\n" + "6.4,3.2,4.5,1.5,versicolor\n"
>>         + "6.9,3.1,4.9,1.5,versicolor\n" +
>>         "5.5,2.3,4,1.3,versicolor\n" + "6.5,2.8,4.6,1.5,versicolor\n"
>>         + "5.7,2.8,4.5,1.3,versicolor\n" +
>>         "6.3,3.3,4.7,1.6,versicolor\n" + "4.9,2.4,3.3,1,versicolor\n"
>>         + "6.6,2.9,4.6,1.3,versicolor\n" +
>>         "5.2,2.7,3.9,1.4,versicolor\n" + "5,2,3.5,1,versicolor\n" +
>>         "5.9,3,4.2,1.5,versicolor\n" + "6,2.2,4,1,versicolor\n" +
>>         "6.1,2.9,4.7,1.4,versicolor\n" +
>>         "5.6,2.9,3.6,1.3,versicolor\n" +
>>         "6.7,3.1,4.4,1.4,versicolor\n" + "5.6,3,4.5,1.5,versicolor\n"
>>         + "5.8,2.7,4.1,1,versicolor\n" +
>>         "6.2,2.2,4.5,1.5,versicolor\n" +
>>         "5.6,2.5,3.9,1.1,versicolor\n" +
>>         "5.9,3.2,4.8,1.8,versicolor\n" + "6.1,2.8,4,1.3,versicolor\n"
>>         + "6.3,2.5,4.9,1.5,versicolor\n" +
>>         "6.1,2.8,4.7,1.2,versicolor\n" +
>>         "6.4,2.9,4.3,1.3,versicolor\n" + "6.6,3,4.4,1.4,versicolor\n"
>>         + "6.8,2.8,4.8,1.4,versicolor\n" + "6.7,3,5,1.7,versicolor\n"
>>         + "6,2.9,4.5,1.5,versicolor\n" + "5.7,2.6,3.5,1,versicolor\n"
>>         + "5.5,2.4,3.8,1.1,versicolor\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" + "5.4,3,4.5,1.5,versicolor\n"
>>         + "6,3.4,4.5,1.6,versicolor\n" +
>>         "6.7,3.1,4.7,1.5,versicolor\n" +
>>         "6.3,2.3,4.4,1.3,versicolor\n" + "5.6,3,4.1,1.3,versicolor\n"
>>         + "5.5,2.5,4,1.3,versicolor\n" +
>>         "5.5,2.6,4.4,1.2,versicolor\n" + "6.1,3,4.6,1.4,versicolor\n"
>>         + "5.8,2.6,4,1.2,versicolor\n" + "5,2.3,3.3,1,versicolor\n" +
>>         "5.6,2.7,4.2,1.3,versicolor\n" + "5.7,3,4.2,1.2,versicolor\n"
>>         + "5.7,2.9,4.2,1.3,versicolor\n" +
>>         "6.2,2.9,4.3,1.3,versicolor\n" + "5.1,2.5,3,1.1,versicolor\n"
>>         + "5.7,2.8,4.1,1.3,versicolor\n" + "6.3,3.3,6,2.5,virginica\n"
>>         + "5.8,2.7,5.1,1.9,virginica\n" + "7.1,3,5.9,2.1,virginica\n"
>>         + "6.3,2.9,5.6,1.8,virginica\n" + "6.5,3,5.8,2.2,virginica\n"
>>         + "7.6,3,6.6,2.1,virginica\n" + "4.9,2.5,4.5,1.7,virginica\n"
>>         + "7.3,2.9,6.3,1.8,virginica\n" +
>>         "6.7,2.5,5.8,1.8,virginica\n" + "7.2,3.6,6.1,2.5,virginica\n"
>>         + "6.5,3.2,5.1,2,virginica\n" + "6.4,2.7,5.3,1.9,virginica\n"
>>         + "6.8,3,5.5,2.1,virginica\n" + "5.7,2.5,5,2,virginica\n" +
>>         "5.8,2.8,5.1,2.4,virginica\n" + "6.4,3.2,5.3,2.3,virginica\n"
>>         + "6.5,3,5.5,1.8,virginica\n" + "7.7,3.8,6.7,2.2,virginica\n"
>>         + "7.7,2.6,6.9,2.3,virginica\n" + "6,2.2,5,1.5,virginica\n" +
>>         "6.9,3.2,5.7,2.3,virginica\n" + "5.6,2.8,4.9,2,virginica\n" +
>>         "7.7,2.8,6.7,2,virginica\n" + "6.3,2.7,4.9,1.8,virginica\n" +
>>         "6.7,3.3,5.7,2.1,virginica\n" + "7.2,3.2,6,1.8,virginica\n" +
>>         "6.2,2.8,4.8,1.8,virginica\n" + "6.1,3,4.9,1.8,virginica\n" +
>>         "6.4,2.8,5.6,2.1,virginica\n" + "7.2,3,5.8,1.6,virginica\n" +
>>         "7.4,2.8,6.1,1.9,virginica\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\n" + "7.7,3,6.1,2.3,virginica\n"
>>         + "6.3,3.4,5.6,2.4,virginica\n" +
>>         "6.4,3.1,5.5,1.8,virginica\n" + "6,3,4.8,1.8,virginica\n" +
>>         "6.9,3.1,5.4,2.1,virginica\n" + "6.7,3.1,5.6,2.4,virginica\n"
>>         + "6.9,3.1,5.1,2.3,virginica\n" +
>>         "5.8,2.7,5.1,1.9,virginica\n" + "6.8,3.2,5.9,2.3,virginica\n"
>>         + "6.7,3.3,5.7,2.5,virginica\n" + "6.7,3,5.2,2.3,virginica\n"
>>         + "6.3,2.5,5,1.9,virginica\n" + "6.5,3,5.2,2,virginica\n" +
>>         "6.2,3.4,5.4,2.3,virginica\n" + "5.9,3,5.1,1.8,virginica\n";
>>         List tableRead = rConnection.eval( "read.csv(textConnection(""
>>         + inputIris + ""), header = FALSE)").asList(); // 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(); String[] d5 = ((REXPVector)
>>         ((RList) tableRead).get(4)).asStrings(); // create data frame
>>         with data.REXP myDf = REXP.createDataFrame(new RList( new
>>         REXP[] { new REXPDouble(d1), new REXPDouble(d2), new
>>         REXPDouble(d3), new REXPDouble(d4), new REXPString(d5) })); //
>>         assign the data to a variable as was
>>         suggested.rConnection.assign("boxMVariable", myDf); // create
>>         a string command with that variable name.String boxVariable =
>>         "boxM(boxMVariable [,-5], boxMVariable[,5]"; // try to execute
>>         the command... // FAILS with
>>         org.rosuda.REngine.Rserve.RserveException: eval failed,
>>         request status: R parser: input incomplete>>>> FAILS ! >>>>
>>         REXP theBoxMResult = rConnection.eval(boxVariable); <<<< FAILS
>>         <<<<< sent from ProtonMail <https://protonmail.com>,
>>         Swiss-based encrypted email. [[alternative HTML version
>>         deleted]]
>>         ------------------------------------------------------------------------
>>         R-devel at r-project.org <mailto:R-devel at r-project.org> mailing
>>         list https://stat.ethz.ch/mailman/listinfo/r-devel |
>>
>>
>



[Rd] Cannot Compute Box's M (Three Days Trying...)
Duncan Murdoch