1

I have this R script:

palindrome <- function(p) {
  for(i in 1:floor(nchar(p)/2) ) {
    r <- nchar(p) - i + 1
    if ( substr(p, i, i) != substr(p, r, r) ) return(FALSE) 
  }
  return(TRUE)
}

that I am calling from Java using the following code:

connection.serverSource("C:\\Users\\x\\Desktop\\R Script\\Palindrome.R");

the connection is of type RConnection is created as follows:

public void startConnection() {
        PATH_TO_R = SystemUtils.IS_OS_UNIX ? "R" : "C:\\Program Files\\R\\R-3.6.1\\bin\\x64\\R.exe";    
        try {
            String cmd = PATH_TO_R + " -e " + "\"library(Rserve);Rserve(port=" + 6311+ ")\"";
            Runtime.getRuntime().exec(cmd);
            RConnection connection = new RConnection("localhost", 6311);
        } catch (IOException | RserveException e) {
            e.printStackTrace();
        }
}

The problem is I am having this error thrown and have no idea how to fix it:

org.rosuda.REngine.Rserve.RserveException: serverSource failed, request status: control pipe to master process is closed/broken

any help will be much appreciated!

AMAY
  • 67
  • 1
  • 7

1 Answers1

0

The function serverSource (just like serverEval and serverShutdown) directly works on the main R+Rserve process, this feature is off by default. You can enable it in /etc/Rserv.conf adding the line control enabled (config reference).

If you don't already use an Rserve config file, you can simply create it in the default location /etc/Rserv.conf (linux/macOS) or create it anywhere (also windows) and pass the location as parameter when starting Rserve: R CMD Rserve --RS-conf <your path here> (command line arguments at the bottom of the page).

karo
  • 56
  • 4