Listing R Package Dependencies Without Installing Packages

Listing R Package Dependencies Without Installing Packages

You can use the result of the available.packages function. For example, to see what ggplot2 depends on :

pack <- available.packages()
pack["ggplot2","Depends"]

Which gives :

[1] "R (>= 2.14), stats, methods"

Note that depending on what you want to achieve, you may need to check the Imports field, too.

List the dependencies of a package regardless of how it is loaded or installed

The pacman package that I maintain does this:

if (!require("pacman")) install.packages("pacman")
pacman::p_depends(dplyr)

$Imports
[1] "assertthat" "bindrcpp" "glue" "magrittr" "methods"
[6] "pkgconfig" "rlang" "R6" "Rcpp" "tibble"
[11] "utils"

$LinkingTo
[1] "Rcpp" "BH" "bindrcpp" "plogr"

$Suggests
[1] "bit64" "covr" "dbplyr" "dtplyr"
[5] "DBI" "ggplot2" "hms" "knitr"
[9] "Lahman" "mgcv" "microbenchmark" "nycflights13"
[13] "rmarkdown" "RMySQL" "RPostgreSQL" "RSQLite"
[17] "testthat" "withr"

Offline installation of a list of packages: getting dependencies in order

The package miniCRAN can help with this. You tell miniCRAN the list of packages you would ever want to install, it then figures out the dependencies, downloads those packages and creates a repository on your local machine that behaves like CRAN, i.e. it respects install.packages() etc.

More information:

  • Available on CRAN

  • Read the vignette

  • We are actively developing miniCRAN. Track progress and find the latest development version at github miniCRAN repository

  • See the project wiki for links to presentations, blog posts and more

To install from the local miniCRAN repository, you have two options.

  1. Firstly, you can use the URI convention file:///. e.g.

    install.packages("ggplot2", repos="file:///path/to/file/")
  2. Alternatively, you can configure the destination as an HTTP server and make your repository available via a URL. In this case, your local repository will look and feel exactly like a CRAN mirror, other than it only contains your desired packages.

Possible to install a package without installing dependencies?

You cannot install and get a package to work without its dependencies. The dependencies= parameter is really an indicator if you would like R to automatically install the dependencies. If set to FALSE, R still stop and warn you so you can decide what you would like to do; if TRUE, R will automatically try to download from your current CRAN repository mirror. With repos=NULL (a local file install) there is nowhere else to look for dependencies so the dependencies= parameter is ignored.

Only download sources of a package and all dependencies

There are now better options for this in the tools package that comes with base R: package_dependencies(). See for example, the Answer from @sebastian-c and this recent Q&A for a related use-case.


There is an unexported getDependencies() function in the utils package. I haven't studied how it works, but combining that with @Dirk's Answer should get you most of the way there.

Basically though, it appears you use it like:

utils:::getDependencies(pkgs, dependencies, available, lib)

where pkgs is the character vector of packages to install, dependencies is a character vector of types of dependencies (Depends, Enhances etc) that you want, available is the output from available.packages() and lib is the library location for the packages within which dependencies are evaluated.

If you debug install.packages() it is basically doing the getDependencies() step then @Dirk's download.packages() step before it actually starts installing anything.

Package dependencies when installing from source in R

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.



Related Topics



Leave a reply



Submit