Larry Martell
2017-Nov-29 14:28 UTC
[R] Preventing repeated package installation, or pre installing packages
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? 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. [[alternative HTML version deleted]]
Michael Dewey
2017-Nov-29 16:05 UTC
[R] Preventing repeated package installation, or pre installing packages
Dear Larry As far as your first question is concerned I think one of require or requireNamespace may be what you need. Michael On 29/11/2017 14:28, Larry Martell 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? > > 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. > > [[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. >-- Michael http://www.dewey.myzen.co.uk/home.html
Rainer Krug
2017-Nov-29 16:14 UTC
[R] Preventing repeated package installation, or pre installing packages
> 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>
Thierry Onkelinx
2017-Nov-29 16:20 UTC
[R] Preventing repeated package installation, or pre installing packages
Dear Larry, Have a look at https://github.com/inbo/rstable That is a dockerfile with a stable version of R and a set of packages. Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance thierry.onkelinx at inbo.be Kliniekstraat 25, B-1070 Brussel www.inbo.be /////////////////////////////////////////////////////////////////////////////////////////// To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey /////////////////////////////////////////////////////////////////////////////////////////// Van 14 tot en met 19 december 2017 verhuizen we uit onze vestiging in Brussel naar het Herman Teirlinckgebouw op de site Thurn & Taxis. Vanaf dan ben je welkom op het nieuwe adres: Havenlaan 88 bus 73, 1000 Brussel. /////////////////////////////////////////////////////////////////////////////////////////// 2017-11-29 15:28 GMT+01:00 Larry Martell <larry.martell at gmail.com>:> 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? > > 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. > > [[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.
Larry Martell
2017-Dec-08 01:29 UTC
[R] Preventing repeated package installation, or pre installing packages
On Wed, Nov 29, 2017 at 11:14 AM, Rainer Krug <Rainer at krugs.de> wrote:> > > 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.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.
Larry Martell
2017-Dec-08 01:30 UTC
[R] Preventing repeated package installation, or pre installing packages
On Wed, Nov 29, 2017 at 11:20 AM, Thierry Onkelinx <thierry.onkelinx at inbo.be> wrote:> Dear Larry, > > Have a look at https://github.com/inbo/rstable That is a dockerfile > with a stable version of R and a set of packages.Thank you very much. This is very useful to me.> 2017-11-29 15:28 GMT+01:00 Larry Martell <larry.martell at gmail.com>: >> 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? >> >> 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. >> >> [[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.
Seemingly Similar Threads
- Preventing repeated package installation, or pre installing packages
- Preventing repeated package installation, or pre installing packages
- Preventing repeated package installation, or pre installing packages
- Preventing repeated package installation, or pre installing packages
- R: dplyr, doBy, and ggplot2 in CentOS7