1

I have this code :

import org.rosuda.REngine.Rserve.RConnection;


public class TestProgram {

    public static void main(String[] args) {

           try {

               RConnection rConnection = new RConnection(); 
               // make a new local connection on default port (6311)
               rConnection.eval("for(i in 1:.Machine$integer.max){}");
               System.out.println("Done!");

           }
           catch(Exception e) {
               System.out.println(e.toString());
           }

    }


}

I get this exception :

org.rosuda.REngine.Rserve.RserveException: eval failed, request status: error code: 127

If I change :

rConnection.eval("for(i in 1:.Machine$integer.max){}");

to

rConnection.eval("for(i in 1:777){}");

it does work :-)

Does anyone know what's going on ?

P.S I started Rserve from R ( same machine ) using :

>library(Rserve)
>Rserve()
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rserve_1.7-3

loaded via a namespace (and not attached):
[1] tools_3.0.1

OS is Windows 8. I did not try this on Linux.

1
  • Doesn't 1:.Machine$integer.max try to allocate a huge vector, and fail for that reason? Commented Sep 19, 2013 at 7:55

1 Answer 1

2

You should check the return from the eval function to see if it extends try-error. If it does then print it to debug string to get the error message. The section below was taken from the Rserve documentation. This will give you the error message that caused the 127. You should also probably use parseAndEval rather than just eval.

http://www.rforge.net/Rserve/faq.html

c.assign(".tmp.", myCode);
REXP r = c.parseAndEval("try(eval(parse(text=.tmp.)),silent=TRUE)");
if (r.inherits("try-error")) System.err.println("Error: "+r.toString())
else { // success .. }

You might also want to check this link in case it is a restriction of your R environment.

R - Big Data - vector exceeds vector length limit

EDIT: Fixing Chris Hinshaw's answer

c.assign(".tmp.", myCode);
REXP r = c.parseAndEval("try(eval(parse(text=.tmp.)),silent=TRUE)");
if (r.inherits("try-error")) System.err.println("Error: " + r.asString())
else { // success .. }

Note that the println should be using asString(), not toString()

Sign up to request clarification or add additional context in comments.

1 Comment

This solution realy helps, but I had to use: ``` if (r.inherits("try-error")) { System.err.println(((REXPString)r).toDebugString()); } ``` since asString() does not exist and asStrings(), which does exist, does not return the content you are looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.