Install R package from source

I’m trying to install a local R package from source. I added the folllowing line in my docker file
RUN R -e ‘install.packages("/PathToPackage/PackageName.tar.gz", repos = NULL, type = “source”)’.
Installing it in R works fine. But in Docker I get the message:
Warning: invalid package ‘/PathToPackage/PackageName.tar.gz’ Error: ERROR: no packages specified
installation of package ‘/PathToPackage/PackageName.tar.gz’ had non-zero exit status

The error suggests that the package is not available at the specified location.
Note that the package sources need to be available in the Docker image, so you need to have an COPY command beforehand where you copy your package to the Docker image:

COPY PackageName.tar.gz /PathToPackage/PackageName.tar.gz
RUN R -e 'install.packages("/PathToPackage/PackageName.tar.gz", repos = NULL, type = "source")'

Oh, that was easy. Thank you.

1 Like