How can I install a R package on a offline Debian

2020-05-07 04:03发布

问题:

I have an Debian VM which is not connected to internet. Yet, I can still scp any file from my local machine which does have internet connection. To provide a little bit context, I am trying to host an shiny app on the VM.

I can still install an old version of R 3.1.1 with the "apt-get" command:

sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev

Yet, still can't find the "shiny" package when check the list:

sudo apt-cache search "^r-.*" | sort

So, I am thinking whether I could just scp the "shiny.tar.gz" to the VM and install the package locally? How could I install any R package offline?

I have tried somethings like:

install.packages('/home/mli/R/dir_pkg/shiny/shiny_0.13.2.tar.gz', repos = NULL, type = "source")

Yet, it didn't go through and error message as below:

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in type == "both" : 
comparison (1) is possible only for atomic and list types
Calls: install.packages
Execution halted

Then, I tried it with another "R CMD":

R CMD INSTALL /home/mli/R/dir_pkg/shiny/shiny_0.13.2.tar.gz

I got error message telling me that dependencies is missing:

* installing to library ‘/home/mli/R/x86_64-pc-linux-gnu-library/3.1’
ERROR: dependencies ‘httpuv’, ‘mime’, ‘jsonlite’, ‘xtable’, ‘digest’, ‘htmltools’, ‘R6’ are not available for package ‘shiny’
* removing ‘/home/mli/R/x86_64-pc-linux-gnu-library/3.1/shiny’

How can I successfully install shiny package from source? Should I go ahead to install all dependencies and dependencies of dependencies first?

回答1:

Shiny has a few package dependencies, and "R CMD INSTALL" won't find them for you, so you need to get them manually. According to the description of shiny, it's dependencies are: 'Rcpp’, ‘httpuv’, ‘mime’, ‘jsonlite’, ‘xtable’, ‘digest’, ‘htmltools’, ‘R6’. So first, get the packages from cran (below are current versions, but they do change over time. Note below is for the computer connected to the internet, you'll need to scp these to the offline computer before continuing):

wget https://cran.r-project.org/src/contrib/Rcpp_0.12.4.tar.gz 
wget https://cran.r-project.org/src/contrib/httpuv_1.3.3.tar.gz 
wget https://cran.r-project.org/src/contrib/mime_0.4.tar.gz 
wget https://cran.r-project.org/src/contrib/jsonlite_0.9.19.tar.gz 
wget https://cran.r-project.org/src/contrib/digest_0.6.9.tar.gz 
wget https://cran.r-project.org/src/contrib/htmltools_0.3.5.tar.gz 
wget https://cran.r-project.org/src/contrib/R6_2.1.2.tar.gz 
wget https://cran.r-project.org/src/contrib/shiny_0.13.2.tar.gz

Then go through them in that same order with R CMD INSTALL. eg:

R CMD INSTALL Rcpp_0.12.4.tar.gz

Once all the dependencies are there, R CMD INSTALL should let you install shiny.



回答2:

To install some package-offline on Debian you can use apt-offline :

apt-offline can fully update and upgrade an APT based distribution without connecting to the network, all of it transparent to APT.

apt-offline can be used to generate a signature on a machine (with no network). This signature contains all download information required for the APT database system. This signature file can be used on another machine connected to the internet (which need not be a Debian box and can even be running windows) to download the updates. The downloaded data will contain all updates in a format understood by APT and this data can be used by apt-offline to update the non-networked machine.

Install apt-offline on the offline os (Debian) then type the following command (to import missing keys) :

sudo apt-key exportall | sudo gpg --no-default-keyring --import --keyring /etc/apt/trusted.gpg

Then you need to get the signature of your_package_name:

apt-offline set debian-install.sig --install-packages your_package_name

Next step ,Upload debian-install.sig to the on-line system and download required files.

apt-offline get debian-install.sig --bundle debian-install.zip 

Upload debian-install.zip file to the off-line system, install it using apt-offline utility to update APT database.

sudo apt-offline install debian-install.zip 

install the specified packages your_package_name :

sudo apt-get install your_package_name

You can download your package using windows machine tuto



回答3:

You are in a pickle. The R package mechanism expects you to be connected to get dependencies. That said, you can get some help:

R> AP <- available.packages(contrib.url(options("repos")$repos[1]))
R> revs <- tools::package_dependencies("shiny", AP, recursive=TRUE)[[1]]
R> revs
 [1] "methods"   "utils"     "httpuv"    "mime"     
 [5] "jsonlite"  "xtable"    "digest"    "htmltools"
 [9] "R6"        "Rcpp"      "tools"     "stats"    
R> 

You can now look into AP again and feed this into download.packages().

Also, several (all ?) of these are in a newer Debian distro so you could use apt-get in download-mode (maybe using apt-offline as suggested in the other question).

Lastly, we do offer a Docker container for shiny so if you use that on your VM you don't need anything else.



回答4:

sudo apt-get update

sudo apt-get install r-cran-digest


I can`t belive that it was so easy. I spent a long time searching and got only bad answers. This commands just solve everything. I used it on trisquel