简体   繁体   中英

Docker install.packages R on Ubuntu 22.04 packages not found

I have the docker command to install R packages:

RUN R -e "install.packages(c("readxl","zoo","plotly","RcppRoll","shiny","tidyverse"\
,"shinyWidgets","shinythemes","metR","writexl","shinydashboard","lubridate","sjmisc"\
,"DBI","dplyr","dbplyr","odbc"), repos='https://cloud.r-project.org/')"

I get the error

install.packages(c(readxl,zoo,plotly,RcppRoll,shiny,tidyverse,shinyWidgets,shinythemes,metR,writexl,shinydashboard,lubridate,sjmisc,DBI,dplyr,dbplyr,odbc), repos='https://cloud.r-project.org/') Error in install.packages(c(readxl, zoo, plotly, RcppRoll, shiny, tidyverse, : object 'readxl' not found Execution halted

Where is the error? R runs fine without docker.

You are falling victim to shell quoting, sometimes called shell quoting hell. The fact that, as you say, "R runs fine without docker" just means you have the right command inside R, but not from the shell. Witness

$ Rscript -e "cat("Hello, world\n")"
Error: unexpected end of input
Execution halted
$ 

but (method 1) escaping quotes works:

$ Rscript -e "cat(\"Hello, world\n\")"
Hello, world
$ 

or (method 2) wrapping double quotes in single quotes

$ Rscript -e 'cat("Hello, world\n")'
Hello, world
$ 

So I would try

RUN R -e 'install.packages(c("readxl","zoo","plotly","RcppRoll","shiny", 
          "tidyverse",    "shinyWidgets","shinythemes","metR","writexl",
          "shinydashboard","lubridate","sjmisc", "DBI", "dplyr", 
          "dbplyr", "odbc"), repos="https://cloud.r-project.org/")'

As an aside you may also want to look into r2u to have all this done as binaries (..) on Ubuntu 22.04 or 20.04.

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