R package in Dockerfile: couldn't find package 'tidyverse/googlesheets4' - r

I managed to install the following package on my local RStudio session:
install.packages("devtools")
devtools::install_github("tidyverse/googlesheets4")
I am now trying to install it directly in the Dockerfile of my RStudio session on my server.
For that, below the line:
RUN R -e "install.packages(c('DT', 'shiny', 'DBI', 'devtools'))"
I have added:
RUN R -e "devtools::install_version('tidyverse/googlesheets4')"
But when I launch the docker-compose up -d command I get this error:
Error in package_find_repo(package, repos) : couldn't find package
'tidyverse/googlesheets4' Calls: ... ->
download_version_url -> package_find_repo Execution halted ERROR:
Service 'rstudio' failed to build: The command '/bin/sh -c R -e
"devtools::install_version('tidyverse/googlesheets4')"' returned a
non-zero code: 1
Do you know what could be the issue?
Thanks a lot.

Related

How to install r package on server

i am trying to install r package in ubuntu to deploy the app in shiny-server with required version i have tried the below code but it was throwing an error
Error: unexpected '/' in "install.packages(http:/"
Execution halted
Code:
sudo su - -c "R -e \"install.packages("http://cran.r-project.org/src/contrib/Archive/shinydashboard/shinydashboard_0.6.1.tar.gz", repos=NULL)\""
Is there any other way to install this packages in ubuntu
Try:
sudo su - \
-c "R -e \"install.packages('http://cran.r-project.org/src/contrib/Archive/shinydashboard/shinydashboard_0.6.1.tar.gz',
repos=NULL, type ='source')\""

Unable to install spark with sparklyr in Dockerfile

We are trying to build our own docker image to use R and the tidyverse with Spark. However, we are getting an error in the build when trying to install Spark.
Here is our Dockerfile:
# start with the most up-to-date tidyverse image as the base image
FROM rocker/tidyverse:latest
# install openjdk 8 (Java)
RUN apt-get update \
&& apt-get install -y openjdk-8-jdk
# Install sparklyr
RUN install2.r --error --deps TRUE sparklyr
# Install spark
RUN Rscript -e 'sparklyr::spark_install("2.4.3")'
RUN mv /root/spark /opt/ && \
chown -R rstudio:rstudio /opt/spark/ && \
ln -s /opt/spark/ /home/rstudio/
RUN install2.r --error --deps TRUE DBI
RUN install2.r --error --deps TRUE RPostgres
RUN install2.r --error --deps TRUE dbplyr
We are using Docker compose up to build and then create the container.
When building, it throws the error:
=> ERROR [4/8] RUN Rscript -e 'sparklyr::spark_install("2.3.0")' 62.0s
------
> [4/8] RUN Rscript -e 'sparklyr::spark_install("2.3.0")':
#7 61.85 Error in download.file(installInfo$packageRemotePath, destfile = installInfo$packageLocalPath, :
#7 61.85 download from 'https://archive.apache.org/dist/spark/spark-2.3.0/spark-2.3.0-bin-hadoop2.7.tgz' failed
#7 61.85 Calls: <Anonymous>
#7 61.85 Execution halted
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c Rscript -e 'sparklyr::spark_install("2.3.0")']: exit code: 1
We have also tried running it as:
RUN R -e 'sparklyr::spark_install("2.4.3")'
Instead of:
RUN Rscript -e 'sparklyr::spark_install("2.4.3")'
but it stil throws an error. We have also tried installing different versions of Spark to see if that would work but still no luck. Does anyone know why I am getting this error and how I can properly install spark with sparklyr in docker? Thank you.

Script to run a script in a docker container

The idea is to run a R script in a docker container. The R script works fine. Here is a piece from this R script. The R sript create the file alpha.csv. The script doesn*t start. If I run the script by hand from the root dir Rscript /home/script/master.R I get an error message.
The error message
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/alpha.csv': No such file or directory
Execution halted
I copyy the script to /home/master.r in the container
Here is my dockerfile
From rocker/r-base:latest
# Create directories
RUN mkdir -p home/data home/output home/script
# Copy files
COPY /src/data/test.csv /home/data/test.csv
COPY /src/master.R /home/script/master.R
COPY /src/install_packages.R /home/script/install_packages.R
# Install R-packages
RUN Rscript /home/script/install_packages.R
# Run the script
CMD Rscript /home/script/master.R
The second problem is, that I need groff. So I tried this:
install.packages('groff', dependencies = TRUE, repos='http://cran.us.r-project.org')
Te error message
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning message:
package ‘groff’ is not available (for R version 3.6.1)
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning message:
package ‘pandoc’ is not available (for R version 3.6.1)
How do I run the container.? I tried this:
docker run -it --rm test
Concerning the first issue, you should set the WORKDIR directive to /home/script, concerning groff, I'm not aware of any R package with that name but I'm familiar with the command itself and I think you want to have that installed.
This should be the resulting Dockerfile:
FROM rocker/r-base:latest
RUN apt-get update \
&& apt-get install -yq --no-install-recommends groff \
&& rm -rf /var/lib/apt/lists/*
# Create directories
RUN mkdir -p /home/data /home/output /home/script
WORKDIR /home/script
# Install R-packages
COPY ./src/install_packages.R /home/script/install_packages.R
RUN Rscript /home/script/install_packages.R
# Copy data
COPY ./src/data/test.csv /home/data/test.csv
COPY /src/master.R /home/script/master.R
# Run the script
CMD Rscript /home/script/master.R
Concerning the Dockerfile writing, I'd suggest you check https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
If your data.csv file changes often, I suggest to avoid copying it in the docker image but to mount the folder when the container starts. I suppose you want to access the output files once you're done with the execution, then I suppose you should mount the output folder as well. You can take this commands as examples:
docker build --tag newtest .
docker run \
-it --rm \
-v "$(pwd)/src/data/:/home/data/" \
-v "$(pwd)/src/output/:/home/output/" \
newtest

Install packages from source failing - Dockerfile

I am trying to install some packages from source (including package that I have created that installed fine with R console or even when R CMD install.
However, while building docker-image using a docker file. I get this error with for this line in the docker file
RUN R -e 'install.packages("RcppDIUtilsPackage_1.0.tar.gz",repos=NULL,type="source")'
I also tried many other commands including R CMD INSTALL all work fine to install the package except within the docker image build.
Here is the error i am encountering.
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning: invalid package ‘RcppDIUtilsPackage_1.0.tar.gz’
Error: ERROR: no packages specified
Warning message:
In install.packages("RcppDIUtilsPackage_1.0.tar.gz", repos = NULL, :
installation of package ‘RcppDIUtilsPackage_1.0.tar.gz’ had non-zero exit status
Thanks!!
Edit: The Dockerfile
FROM rocker/r-ver:3.4.4
WORKDIR /home/ubuntu/projects/DService
RUN apt-get update -qq && apt-get install -y \
libssl-dev \
libcurl4-gnutls-dev
RUN R -e "install.packages('plumber')"
RUN R -e "install.packages('Rcpp')"
RUN R -e 'install.packages("RcppDIUtilsPackage_1.0.tar.gz",repos=NULL,type="source")'
COPY / /
EXPOSE 8000
CMD ["Rscript", "DService.R"]
command: sudo docker build --no-cache -t dservice-docker-image .
This is an indirect solution to your problem, because I was not able to resolve the same issue.
The root of the issue may have something to do with the host environment that created the Docker image from the Dockerfile. Specifically, the R instance that is spun up to install the local packages may not being able to access the path to where your local packages are stored.
The solution for me was to just avoid local packages. Move any local repositories to remote repositories, and reference them in the Dockerfile instead. e.g.
RUN R -e "devtools::install_github('dmanuge/shinyFilesWidget') ; system('echo 14')"
After that, rebuilt your Docker image and run it accordingly. While this is not a direct solution, I reached the critical threshold of debugging and needed to move on. :)

installing ropensci/magick behind a firewall

I'm attempting to use the gganiminate library and I'm having an issue when I call gganimate::gganimate(myplot). The issue appears to be with a dependency library, magick.
When I call the function I get the following warning:
gganimate::gganimate(p)
1: running command 'C:\WINDOWS\system32\cmd.exe /c convert --version' had status 4
2: In find_magic() : ImageMagick not installed yet!
In im.convert(img.files, output = path.expand(movie.name), ... :
Please install ImageMagick first or put its bin path into the system PATH variable
So I try to install magick separately. I'm on a machine at a client so installing packages from github requires me to provide info to get through the firewall. I've installed other libraries from github with this machine using the same technique successfully. However, magick appears to be bumping into other problems. Below is my code and the error:
devtools::install_github("ropensci/magick",httr::set_config(httr::use_proxy("xx.xxx.xx.xx",xxxx)))
Downloading GitHub repo ropensci/magick#master
from URL https://api.github.com/repos/ropensci/magick/zipball/master
Installing magick
"C:/PROGRA~1/R/R-34~1.3/bin/x64/R" \
--no-site-file --no-environ --no-save \
--no-restore --quiet CMD INSTALL \
"C:/Users/r631265/AppData/Local/Temp/1/RtmpS0efnQ/devtools18fc5f2414b/ropensci-magick-7925af3" \
--library="C:/Users/r631265/Documents/R/win-library/3.4" \
--install-tests
* installing *source* package 'magick' ...
** libs
*** arch - i386
rm -f RcppExports.o animation.o attributes.o base.o color.o composite.o config.o convolve.o device.o edit.o fonts.o options.o resize.o transformations.o magick.dll
Linking to imagemagagick-6.9.9
"C:/PROGRA~1/R/R-34~1.3/bin/i386/Rscript.exe" "../tools/winlibs.R" 6.9.9
Error in curl::curl_download(sprintf("https://github.com/rwinlib/imagemagick%s/archive/v%s.zip", :
schannel: failed to receive handshake, SSL/TLS connection failed
Calls: <Anonymous> -> .Call
Execution halted
make: *** [winlibs] Error 1
Warning: running command 'make -f "Makevars.win" -f "C:/PROGRA~1/R/R-34~1.3/etc/i386/Makeconf" -f "C:/PROGRA~1/R/R-34~1.3/share/make/winshlib.mk" CXX='$(CXX11) $(CXX11STD)' CXXFLAGS='$(CXX11FLAGS)' CXXPICFLAGS='$(CXX11PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX11LDFLAGS)' SHLIB_LD='$(SHLIB_CXX11LD)' SHLIB="magick.dll" OBJECTS="RcppExports.o animation.o attributes.o base.o color.o composite.o config.o convolve.o device.o edit.o fonts.o options.o resize.o transformations.o"' had status 2
ERROR: compilation failed for package 'magick'
* removing 'C:/Users/r631265/Documents/R/win-library/3.4/magick'
In R CMD INSTALL
Installation failed: Command failed (1)
I think perhaps my firewall details aren't getting passed into: curl::curl_download(sprintf("https://github.com/rwinlib/imagemagick%s/archive/v%s.zip",...)
Network security is a bit of a black box to me so I'm not sure what else to try or if I'm diagnosing the issue correctly. Any help would be greatly appreciated!

Resources