2

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.i.e. sudo -i R can be replaced by R.

Community
  • 1
  • 1
edesz
  • 11,756
  • 22
  • 75
  • 123
  • You can't start R on the CLI at all just because it's remote? I'm not sure why you don't have `sudo` over a VNC connection, but I wasn't aware that `sudo` would even be necessary just to launch R CLI and install packages. Can you verify that? – Hack-R Dec 30 '16 at 14:33
  • I would need to start, install and close the R CLI. I'm not sure how to do this. Also, in my scenario, doesn't it seem more intuitive to install from the Ubuntu CLI? – edesz Dec 30 '16 at 14:35
  • 1
    Well you'd just type `R` then do everything as you normally do. Regarding which one is more intuitive, I guess that's subjective but I can't help you with the `R CMD INSTALL` way because I've never hard to do it that way. *Having said that* in Linux I do often find it more efficient to install packages using `apt` or `yum`. The dependencies are usually non-issue that way and it's often faster. `apt-get install r-cran-ggplot2`, etc. Though I suppose you may need sudo for that too. Is it some company policy or what's preventing you from using `sudo`? – Hack-R Dec 30 '16 at 14:37
  • When I use `install.packages()`, a dialog box opens up asking to select a mirror. In my scenario (remote install), I need to automate this. With your approach, would you specify the repos using `install.packages(c('Rcmdr','list','ggplot2'), dependencies=TRUE, repos = 'http://cran.rstudio.com/')`? Or is there some other site I need to reference for `repos`? – edesz Dec 30 '16 at 14:45
  • 1
    I just left my computer so I cannot verify this but I think that that pop up only happens once and also setting the repo that way should work. I can verify this when I get back to my computer later – Hack-R Dec 30 '16 at 14:47
  • Okay, no problem. Thanks for your help regarding this. Looks like there are a couple of options: a post [here](http://stackoverflow.com/questions/11488174/how-to-select-a-cran-mirror-in-r) mentions using `repos='http://cran.r-project.org'`. – edesz Dec 30 '16 at 15:00

1 Answers1

7

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks. Great answer! – edesz Dec 30 '16 at 16:20
  • My pleasure. There is also a (very low volume) list dedicated to tricks and questions around this: [r-sig-debian](https://stat.ethz.ch/mailman/listinfo/r-sig-debian). You may want to subscribe and lurk. – Dirk Eddelbuettel Dec 30 '16 at 16:21