简体   繁体   中英

Remote install of multiple R packages (with, without depends) from Ubuntu CLI

I have to perform a remote R installation on an Ubuntu 16.10 system. As part of this, I have to install specific packages on that host. I want to install these packages Rcmdr , list , ggplot2 , afex , lsmeans . Since I am doing this remotely, I cannot use

sudo -i R

to first enter the R CLI and then install with install.packages() . Instead I must somehow install the packages from the Ubuntu CLI.

I found these links:

  1. multiple R package installation with install.packages()
  2. R CMD INSTALL -l usage syntax to install multiple packages in section 6.3
  3. Use of repos parameter inside install.packages()

However, some packages have dependencies:

  • The list package depends on utils and sandwich .
  • The Rcmdr package depends on grDevices , utils , splines , RcmdrMisc , car .
  • The ggplot2 package also has dependencies.

I would like to install only the packages Rcmdr , list , ggplot2 with all their dependencies. Normally, I would do it this way:

install.packages(c('Rcmdr','list','ggplot2'), dependencies=TRUE)

QUESTIONS

  1. How do I specify the dependencies option in R CMD for one package only? Is this the way to install them

     R CMD INSTALL -l Rcmdr dependencies=TRUE, list dependencies=TRUE, \\ ggplot2 dependencies=TRUE, afex, lsmeans 

    or this incorrect?

  2. Also, how to I specify the repos parameter inside R CMD INSTALL -l ?

EDIT

As per the first comment below, sudo is not needed above.ie sudo -i R can be replaced by R .

Regarding your questions:

Question 1

This may not be the best approach. Consider instead Rscript -e 'install.packages(...)' which is what R CMD INSTALL ... calls anyway. You have better control over options here. And read on...

Question 2

On all Ubuntu machines at work and home I do this via /etc/R/Rprofile.site via something like

## Example of Rprofile.site
local({
    r <- getOption("repos")
    r["CRAN"] <- "https://cloud.r-project.org"
    r["ghrr"] <- "https://ghrr.github.io/drat"
    options(repos = r)
})

where we usually add a third and network-local repo. You may just want CRAN here -- it uses the 'always-close to you' CDN administered by RStudio for the R Project and R Consortium. The ghrr drat is a helper repo I set up.

Question 3

sudo is not needed per something I add to the official Debian/Ubuntu package for R -- but you need to be a member of the group that owns /usr/local/lib/R/site-library .

Now, if I may, two more suggestions:

Littler

The r executable is available to you via sudo apt-get install r-cran-littler . I use it on the command-line; and you probably want to look into the basic install.r script and the extended install2.r . I tend to create a softlink from /usr/local/bin to the package directory for these and other (such as update.r ). I have been running many (Ubuntu and Debian) machines like that for many years.

Michael Rutter repos, and Docker

We actually have about 3000 CRAN packages as binaries for Ubuntu so you could just do sudo apt-get install ... and all dependendies would get resolved. Look eg in this script of mine (which uses them on Travis) or some of the Docker files I maintain such as this one .

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