Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

r-package

I am looking for a slick way to programmatically get the Imports: and Depends: packages of a package. The trick is that the method should work regardless of whether the package is

  1. installed or just loaded with devtools::load_all(), or
  2. attached or just available through the namespace.

Desired functionality:

package_deps("dplyr")
## [1] "assertthat" "bindrcpp"   "glue"       "magrittr"   "methods"    "pkgconfig" 
## [7] "rlang"      "R6"         "Rcpp"       "tibble"     "utils" 

Notice that the version numbers are all stripped away.

I am writing this post because it seems like this should already exist. (After all, install.packages() needs similar functionality.) I would rather not have to manage all the special cases myself.

like image 882
landau Avatar asked Sep 18 '25 21:09

landau


1 Answers

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"         
like image 99
Tyler Rinker Avatar answered Sep 20 '25 13:09

Tyler Rinker