[R] Preventing repeated package installation, or pre installing packages

Rainer Krug Rainer at krugs.de
Wed Nov 29 17:14:55 CET 2017



> On 29 Nov 2017, at 15:28, Larry Martell <larry.martell at gmail.com> wrote:
> 
> I have a R script that I call from python using rpy2. It uses dplyr, doBy,
> and ggplot2. The script has install.packages commands for these 3 packages.
> Even thought the packages are already installed it still downloads,
> builds, and installs them, which is very time consuming. Is there a way to
> have it only do the install if the package is not already installed?

You could use something like


if (!require(dplyr)) {
install.packages(“dplyr”)
library(dplyr)
}

where require() returns FALSE if it fails to load the package.


> 
> Also, I run in a docker container, so after the container is instantiated
> the packages are not there the first time the script runs. Is there a way
> to pre load the packages, in which case I would not need the
> install.packages commands for these packages and my above question would
> become moot.

Yes - add them to you Docker file, but this is a docker question, not R. Check out the Rocker Dockerfiles to see how you can do this.

Rainer

> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

University of Zürich

Cell:       +41 (0)78 630 66 57
email:      Rainer at krugs.de
Skype:      RMkrug

PGP: 0x0F52F982



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: Message signed with OpenPGP
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20171129/4ecc1b87/attachment.sig>


More information about the R-help mailing list