Search code examples
rrserve

Unable to write data to csv using Rserve


I am able to perform Remote command execution and function calling in R script through Rserve in my Java application. But when my function is trying to save a dataframe in a csv file using

write.csv(MyData, file = "MyData.csv")

They MyData.csv file is not being generated, and no error is showing. when i am executing the same steps in R console, it working fine.

The Rserve is running in my local machine itself and I am using the following to connect and execute:

RConnection connection = new RConnection();
connection.eval("makecsv()")

p.s. I've omitted the "source the R script" step above

Just for reference this is my Dummy R script that I'm trying to run:

makecsv <- function(){
        x<-rnorm(10)
        y<-rnorm(10)
        df1<-data.frame(x,y)
        write.csv(df1, file = "MyData.csv")
        return(df1)
}

Solution

  • Probably you have to use the absolute path, something like this:

    write.csv(MyData, file = "/var/MyData.csv")