On Wed, Nov 29, 2017 at 11:14 AM, Rainer Krug <rai...@krugs.de> wrote: > > > On 29 Nov 2017, at 15:28, Larry Martell <larry.mart...@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.
Thanks that worked perfectly. > 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. What I did not know was how to load a R package from the command line. Thanks to Thierry Onkelinx's answer I now do know. ______________________________________________ R-help@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.