0

I am trying to call a R script from a Java program in Ecplise (Mars Release (4.5.0), jdk1.8.0_45) using

Process pid = Runtime.getRuntime().exec("C:\\Program Files\\R\\R-3.3.1\\bin\\Rscript C:\\path\\HSConcordance.R");

R script file (HSConcordance.R)

file.path = Sys.getenv("R_FILE")
setwd(file.path)
data = read.table("hscode1.csv", sep = ",", header = TRUE, na.strings = c(NA,""), colClasses = c(rep("character",4)))
dim(data)
str(data)
head(data)
write.table(data, file = "submission.csv", col.names = TRUE, row.names = FALSE, sep = ",")

It is simply importing a csv file and writing its contents to another file.

When I am trying to execute R script from the console using

C:\Program Files\R\R-3.3.1\bin>Rscript C:\path\HSConcordance.R

it is working fine creating the output file. But when I am trying to execute it from java, its not getting executed without showing any exception or error.

Do I need to install something to make it work? I have gone through rJava, Rserve, Rcaller but I don't want to use these to call a R script file from java.

Any kind of help will be greatly appreciated.

Rana
  • 505
  • 1
  • 5
  • 19
  • Rana - I dont know enough about Java but does this answer with a Rout workaround help to see what errors you are getting? http://stackoverflow.com/a/14167417/4606130. Sorry I have only used Rscript directly in Windows command line. – micstr Oct 07 '16 at 10:40
  • What happens if you try to use the overloaded variant of the exec() method that takes arguments as an array of Strings? i.e. exec(new String[] { "C:\\Program Files\\R\\R-3.3.1\\bin\\Rscript", "C:\\path\\HSConcordance.R" }); – hammerfest Oct 07 '16 at 11:42
  • @hammerfest Nothing new. R script is not getting executed. I tried with ProcessBuilder as well `ProcessBuilder pid = new ProcessBuilder("C:\\Program Files\\R\\R-3.3.1\\bin\\Rscript.exe", "C:\\Users\\soghosh\\Desktop\\HSConcordance.R");` but no output. – Rana Oct 07 '16 at 11:59

0 Answers0