简体   繁体   中英

How to run “write.csv” on an Rscript while in docker?

I am trying to run a logistic regression model through docker and generate a csv file at the end with the results, to be put in a output folder in the docker image. However, I can't get it to generate the csv because I keep getting this error:

Warning message:
In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  :
  prediction from a rank-deficient fit may be misleading
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
Calls: write.csv -> eval.parent -> eval -> eval -> write.table -> file
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'output/predictions.csv': No such file or directory

Why would I need the csv file to already be in the image, if I am trying to generate it? Is there a way to get around this at all?

Here is my R code for generating the model results:

predictAll = predict(model1, type="response", newdata = RatioData)
id <- RatioData$id
predictAllframe <- data.frame(id, predictAll)
write.csv(predictAllframe, file = 'output/predictions.csv', row.names=FALSE)

and here is my dockerfile:

FROM rocker/verse:latest

#R packages
RUN R -e "install.packages('mosaic', repos = 'http://cran.us.r-project.org')"
RUN R -e "install.packages('plyr', repos = 'http://cran.us.r-project.org', dependencies=T)"
RUN R -e "install.packages('dplyr', repos = 'http://cran.us.r-project.org')"
RUN R -e "install.packages('purrr', repos = 'http://cran.us.r-project.org')"
RUN R -e "install.packages('ggplot2', repos = 'http://cran.us.r-project.org')"
RUN R -e "install.packages('caret', repos = 'http://cran.us.r-project.org')"
RUN R -e "install.packages('e1071', repos = 'http://cran.us.r-project.org')"

# Move to the app folder
RUN mkdir /app
WORKDIR /app

# Copy and run the Rscript.
COPY /src/model-1.R .
CMD R -e "source('/src/model-1.R')"

#data
ADD /data1.tar.gz .

# Copy Bash scripts expected by the IT infrastructure
COPY model1command.sh .

# Add executable permission to Bash scripts
RUN chmod +x model1command.sh

The model1command.sh file just contains the following command:

#!/usr/bin/env Rscript

Rscript /app/model-1.R

and the docker run command that I used is below:

docker run \
     -v $(pwd)/data1:/data:ro \
     -v $(pwd)/output:/output:rw \
     -v $(pwd)/scratch:/scratch:rw \
     awesome-model:v1 bash /app/model1command.sh

Thank you so much, I have been trying to figure this out for almost a week.

The route is not formatted correctly, leave any file in R console and copy the correct name, after replace this name in write.table , for example:

Write.table = (filename, "paste rute"_nombre.csv", row.names=F)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM