Package dependencies when installing from source in R
Asked Answered
D

4

23

Just confirming: If I distribute my R package as ZIP/TAR then installing the package will not automatically download/install dependencies because I have to set repos = NULL in install.packages() and dependencies parameter is not used if repos = NULL? The way to possibly get this to work is to package an install script. Is that possible? Am I completely missing something here and there is a mechanism to install from source AND automagically download and install dependencies?

Durman answered 27/4, 2011 at 13:38 Comment(0)
P
9

You could make your own repository and set repos to be a vector of the places to look for packages, where it would start with your own repository and then include a link to a CRAN mirror. This is what I do and it works quite nicely, as then I can easily share my packages with others and update them from whatever computer I happen to be on.

Primrosa answered 27/4, 2011 at 13:47 Comment(6)
clever! Can my own repository be password protected or otherwise ensure private access only (to clients outside of my firewall)Durman
I really don't know, sorry. Mine is public. I know R gets the packages over http, so if you can limit web access to the approved clients, that should also limit access to your repository.Primrosa
thanks for the suggestion! I'm going to avoid the repository approach because of the security issues. My packages are tied to my company. It would be too much work to maintain an IP whitelist. I'll leave this question open for a few days to see if there are any other solutionsDurman
Maybe you could make a really basic package that just has the dependencies you need and make that public. Install that first, get the necessary dependencies, and then install your real package from the file.Primrosa
another clever solution! I'll have to consider that. Ideally I could just have an installation script that calls the package install function for each package (if not already installed) but I don't know if R packages support installation scripts. Not basic stuff, but probably not too hard either.Durman
This answer is good one, just lacks an example. You don't have to publish your private pkg. You can create local repo. @Durman see my answer here https://mcmap.net/q/586129/-install-a-local-r-package-with-dependencies-from-cran-mirrorAker
C
10

The devtools package has a function install. If used on a directory containing the source code for an R package, it will install that package and download any dependencies from CRAN.

Centigram answered 10/4, 2013 at 2:26 Comment(1)
Since the code to do this has already been written, it would sure be nice if R, and it's defacto tooling (R CMD / Rstudio), did some of these things by default.Willow
P
9

You could make your own repository and set repos to be a vector of the places to look for packages, where it would start with your own repository and then include a link to a CRAN mirror. This is what I do and it works quite nicely, as then I can easily share my packages with others and update them from whatever computer I happen to be on.

Primrosa answered 27/4, 2011 at 13:47 Comment(6)
clever! Can my own repository be password protected or otherwise ensure private access only (to clients outside of my firewall)Durman
I really don't know, sorry. Mine is public. I know R gets the packages over http, so if you can limit web access to the approved clients, that should also limit access to your repository.Primrosa
thanks for the suggestion! I'm going to avoid the repository approach because of the security issues. My packages are tied to my company. It would be too much work to maintain an IP whitelist. I'll leave this question open for a few days to see if there are any other solutionsDurman
Maybe you could make a really basic package that just has the dependencies you need and make that public. Install that first, get the necessary dependencies, and then install your real package from the file.Primrosa
another clever solution! I'll have to consider that. Ideally I could just have an installation script that calls the package install function for each package (if not already installed) but I don't know if R packages support installation scripts. Not basic stuff, but probably not too hard either.Durman
This answer is good one, just lacks an example. You don't have to publish your private pkg. You can create local repo. @Durman see my answer here https://mcmap.net/q/586129/-install-a-local-r-package-with-dependencies-from-cran-mirrorAker
B
5

You can use

  devtools::install_local(path)

It can automatically download all the dependencies.

Betatron answered 11/5, 2016 at 16:43 Comment(0)
E
0

If you have a Github account myname, push your R package to a repo mypackage. Then just call devtools::install_github("myname/mypackage"). Package mypackage will be downloaded and installed as will all the dependencies listed under Imports in the DESCRIPTION file.

Enumeration answered 9/12, 2016 at 22:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.