I have just updated the R version on a secure (no internet) server. I would now like to transfer all of my previous packages to the library in my new R version. Of course, these packages need updating and will not run in my new version of R.
I have to install new versions from source, as the server does not have internet access. I have a list of packages I need, and I can download the .tar.gz files onto my local machine and then transfer them into the server. But first I need to get the .tar.gz files and there are hundreds when including all of the dependencies.
I am looking for an easy solution to get all of the .tar.gz files from CRAN without having to visit hundreds of webpages and manually download. Is there an existing method in R to fetch the .tar.gz files? Or can someone think of an easier way for me to do this?
Thanks!
CodePudding user response:
You can use the miniCRAN package.
library(miniCRAN)
mypackages <- rownames(installed.packages())
makeRepo(mypackages, path = "path/to/myrepo", type = "source", Rversion = "4.1")
Then you will get a CRAN-like repository in path/to/myrepo containing the tar.gz files.
CodePudding user response:
This is how to install R packages on a machine without internet access:
Option 1
You can download .tar.gz files of R packages from CRAN e.g. using in bash:
wget https://cran.r-project.org/src/contrib/dplyr_1.0.7.tar.gz
Then, install the package on a machine without internet access:
install.packages("dplyr_1.0.7.tar.gz")
Option 2
Just use install.packages
on an machine with internet access in a R session with the new version (e.g. 4.1). Then you can just copy the directory ~/R/x86_64-pc-linux-gnu-library/4.1/
to the new server without internet access having R 4.1 as well.
Option 3
Please note that the solutions above include only the R code. Some packges (e.g. sf
for spatial data analysis) depend on other system dependencies as well (here GEOS or GDAL). Then I recommend to use R inside docker containers (e.g. rocker/geospatial). Docker containers and their images can be exported into a single tar ball containing all system dependencies.