Skip to content

Dependencies

How to list all dependencies of a CRAN/Bioconductor package?

library(pkgdepends)
prop <- new_pkg_deps("ggplot2")
prop$solve()
prop$get_solution()$data
#>  Updating metadata database ... done                                           
#> # A data frame: 29 × 33                                                         
#>    ref       type  direct direc…¹ status package version license needs…² prior…³
#>    <chr>     <chr> <lgl>  <lgl>   <chr>  <chr>   <chr>   <chr>   <lgl>   <chr>  
#>  1 cli       stan… FALSE  FALSE   OK     cli     3.4.0   MIT + … TRUE    NA     
#>  2 colorspa… stan… FALSE  FALSE   OK     colors… 2.0-3   BSD_3_… TRUE    NA     
#>  3 digest    stan… FALSE  FALSE   OK     digest  0.6.29  GPL (>… TRUE    NA     
#>  4 fansi     stan… FALSE  FALSE   OK     fansi   1.0.3   GPL-2 … TRUE    NA     
#>  5 farver    stan… FALSE  FALSE   OK     farver  2.1.1   MIT + … TRUE    NA     
#>  6 ggplot2   stan… TRUE   TRUE    OK     ggplot2 3.3.6   MIT + … FALSE   NA     
#>  7 glue      stan… FALSE  FALSE   OK     glue    1.6.2   MIT + … TRUE    NA     
#>  8 gtable    stan… FALSE  FALSE   OK     gtable  0.3.1   MIT + … FALSE   NA     
#>  9 isoband   stan… FALSE  FALSE   OK     isoband 0.2.5   MIT + … TRUE    NA     
#> 10 labeling  stan… FALSE  FALSE   OK     labeli… 0.4.2   MIT + … FALSE   NA     
#> # … with 19 more rows, 23 more variables: md5sum <chr>, sha256 <chr>,           
#> #   filesize <int>, built <chr>, platform <chr>, rversion <chr>,                
#> #   repotype <chr>, repodir <chr>, target <chr>, deps <list>, mirror <chr>,     
#> #   sources <list>, remote <list>, error <list>, metadata <list>, extra <list>, 
#> #   dep_types <list>, params <list>, sysreqs <chr>, cache_status <chr>,         
#> #   lib_status <chr>, old_version <chr>, new_version <chr>, and abbreviated     
#> #   variable names ¹​directpkg, ²​needscompilation, ³​priority                  
#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable 
#> names                                                                           

You can also draw a dependency tree:

prop$draw()
#> [31] "│ │ ├─fansi"                                                              
#>                                                                                 
#>                                                                                 
#> [32] "│ │ ├─glue"                                                               
#>                                                                                 
#>                                                                                 
#> [33] "│ │ ├─lifecycle"                                                          
#>                                                                                 
#>                                                                                 
#> [34] "│ │ ├─rlang"                                                              
#>                                                                                 
#>                                                                                 
#> [35] "│ │ ├─utf8 \033[90m1.2.2\033[39m \033[32m[new][bld][cmp][dl] \033[39m\033[
#> 90m(240.33 kB)\033[39m"                                                         
#>                                                                                 
#> [36] "│ │ └─vctrs \033[90m0.4.1\033[39m \033[32m[new][bld][cmp][dl] \033[39m\033
#> [90m(916.78 kB)\033[39m"                                                        
#>                                                                                 
#> [37] "│ │   ├─cli"                                                              
#>                                                                                 
#>                                                                                 
#> [38] "│ │   ├─glue"                                                             
#>                                                                                 
#>                                                                                 
#> [39] "│ │   └─rlang"                                                            
#>                                                                                 
#>                                                                                 
#> [40] "│ ├─pkgconfig \033[90m2.0.3\033[39m \033[32m[new][bld][dl] \033[39m\033[90
#> m(6.08 kB)\033[39m"                                                             
#>                                                                                 
#> [41] "│ ├─rlang"                                                                
#>                                                                                 
#>                                                                                 
#> [42] "│ └─vctrs"                                                                
#>                                                                                 
#>                                                                                 
#> [43] "└─withr \033[90m2.5.0\033[39m \033[32m[new][bld]\033[39m"                 
#>                                                                                 
#>                                                                                 
#> [44] ""                                                                         
#>                                                                                 
#>                                                                                 
#> [45] "Key:  \033[32m[new]\033[39m new | \033[32m[old]\033[39m outdated | \033[32
#> m[dl]\033[39m download | \033[32m[bld]\033[39m build | \033[32m[cmp]\033[39m com
#> pile"                                                                           
#> attr(,"class")                                                                  
#> [1] "tree"      "character"                                                     

How to list all dependencies of a GitHub package?

library(pkgdepends)
prop <- new_pkg_deps("tidyverse/ggplot2")
prop$solve()
prop$get_solution()$data
#>    ref       type  direct direc…¹ status package version license needs…² prior…³
#>    <chr>     <chr> <lgl>  <lgl>   <chr>  <chr>   <chr>   <chr>   <lgl>   <chr>  
#>  1 tidyvers… gith… TRUE   TRUE    OK     ggplot2 3.3.6.… MIT + … TRUE    NA     
#>  2 cli       stan… FALSE  FALSE   OK     cli     3.4.0   MIT + … TRUE    NA     
#>  3 colorspa… stan… FALSE  FALSE   OK     colors… 2.0-3   BSD_3_… TRUE    NA     
#>  4 fansi     stan… FALSE  FALSE   OK     fansi   1.0.3   GPL-2 … TRUE    NA     
#>  5 farver    stan… FALSE  FALSE   OK     farver  2.1.1   MIT + … TRUE    NA     
#>  6 glue      stan… FALSE  FALSE   OK     glue    1.6.2   MIT + … TRUE    NA     
#>  7 gtable    stan… FALSE  FALSE   OK     gtable  0.3.1   MIT + … FALSE   NA     
#>  8 isoband   stan… FALSE  FALSE   OK     isoband 0.2.5   MIT + … TRUE    NA     
#>  9 labeling  stan… FALSE  FALSE   OK     labeli… 0.4.2   MIT + … FALSE   NA     
#> 10 magrittr  stan… FALSE  FALSE   OK     magrit… 2.0.3   MIT + … TRUE    NA     
#> # … with 18 more rows, 23 more variables: md5sum <chr>, sha256 <chr>,           
#> #   filesize <int>, built <chr>, platform <chr>, rversion <chr>,                
#> #   repotype <chr>, repodir <chr>, target <glue>, deps <list>, mirror <chr>,    
#> #   sources <list>, remote <list>, error <list>, metadata <list>, extra <list>, 
#> #   dep_types <list>, params <list>, sysreqs <chr>, cache_status <chr>,         
#> #   lib_status <chr>, old_version <chr>, new_version <chr>, and abbreviated     
#> #   variable names ¹​directpkg, ²​needscompilation, ³​priority                  
#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable 
#> names                                                                           

How to list all dependencies of a local package?

library(pkgdepends)
prop <- new_pkg_deps("local::.")
prop$solve()
prop$get_solution()$data
#> # A data frame: 20 × 33                                                         
#>    ref       type  direct direc…¹ status package version license needs…² prior…³
#>    <chr>     <chr> <lgl>  <lgl>   <chr>  <chr>   <chr>   <chr>   <lgl>   <chr>  
#>  1 local::.  local TRUE   TRUE    OK     pkgdep… 0.3.2   MIT + … NA      NA     
#>  2 callr     stan… FALSE  FALSE   OK     callr   3.7.2   MIT + … FALSE   NA     
#>  3 cli       stan… FALSE  FALSE   OK     cli     3.4.0   MIT + … TRUE    NA     
#>  4 crayon    stan… FALSE  FALSE   OK     crayon  1.5.1   MIT + … FALSE   NA     
#>  5 curl      stan… FALSE  FALSE   OK     curl    4.3.2   MIT + … TRUE    NA     
#>  6 desc      stan… FALSE  FALSE   OK     desc    1.4.2   MIT + … FALSE   NA     
#>  7 filelock  stan… FALSE  FALSE   OK     filelo… 1.0.2   MIT + … TRUE    NA     
#>  8 glue      stan… FALSE  FALSE   OK     glue    1.6.2   MIT + … TRUE    NA     
#>  9 jsonlite  stan… FALSE  FALSE   OK     jsonli… 1.8.0   MIT + … TRUE    NA     
#> 10 lpSolve   stan… FALSE  FALSE   OK     lpSolve 5.6.16  LGPL-2  TRUE    NA     
#> 11 pkgbuild  stan… FALSE  FALSE   OK     pkgbui… 1.3.1   MIT + … FALSE   NA     
#> 12 pkgcache  stan… FALSE  FALSE   OK     pkgcac… 2.0.2   MIT + … TRUE    NA     
#> 13 prettyun… stan… FALSE  FALSE   OK     pretty… 1.1.1   MIT + … FALSE   NA     
#> 14 processx  stan… FALSE  FALSE   OK     proces… 3.7.0   MIT + … TRUE    NA     
#> 15 ps        stan… FALSE  FALSE   OK     ps      1.7.1   MIT + … TRUE    NA     
#> 16 R6        stan… FALSE  FALSE   OK     R6      2.5.1   MIT + … FALSE   NA     
#> 17 rappdirs  stan… FALSE  FALSE   OK     rappdi… 0.3.3   MIT + … TRUE    NA     
#> 18 rprojroot stan… FALSE  FALSE   OK     rprojr… 2.0.3   MIT + … FALSE   NA     
#> 19 withr     stan… FALSE  FALSE   OK     withr   2.5.0   MIT + … FALSE   NA     
#> 20 zip       stan… FALSE  FALSE   OK     zip     2.2.1   MIT + … TRUE    NA     
#> # … with 23 more variables: md5sum <chr>, sha256 <chr>, filesize <int>,         
#> #   built <chr>, platform <chr>, rversion <chr>, repotype <chr>, repodir <chr>, 
#> #   target <chr>, deps <list>, mirror <chr>, sources <list>, remote <list>,     
#> #   error <list>, metadata <list>, extra <list>, dep_types <list>,              
#> #   params <list>, sysreqs <chr>, cache_status <chr>, lib_status <chr>,         
#> #   old_version <chr>, new_version <chr>, and abbreviated variable names        
#> #   ¹​directpkg, ²​needscompilation, ³​priority                                 
#> # ℹ Use `colnames()` to see all variable names                                  

Downloads

How to download a package and all of its dependencies?

library(pkgdepends)
target_dir <- tempfile()
dir.create(target_dir)
prop <- new_pkg_download_proposal("ggplot2", config = list(cache_dir = target_dir))
prop$resolve()
prop$download()
prop$get_downloads()
dir(target_dir)
#>  Got digest 0.6.29 (source) (162.78 kB)                                        
#>  Got glue 1.6.2 (source) (106.51 kB)                                           
#>  Got labeling 0.4.2 (source) (10.16 kB)                                        
#>  Got lifecycle 1.0.1 (source) (99.72 kB)                                       
#>  Got gtable 0.3.1 (source) (92.73 kB)                                          
#>  Got cli 3.4.0 (source) (526.80 kB)                                            
#>  Got magrittr 2.0.3 (source) (267.07 kB)                                       
#>  Got MASS 7.3-58.1 (source) (514.88 kB)                                        
#>  Got munsell 0.5.0 (source) (182.65 kB)                                        
#>  Got pkgconfig 2.0.3 (source) (6.08 kB)                                        
#>  Got R6 2.5.1 (source) (63.42 kB)                                              
#>  Got colorspace 2.0-3 (source) (2.20 MB)                                       
#>  Got RColorBrewer 1.1-3 (source) (11.64 kB)                                    
#>  Got nlme 3.1-159 (source) (846.86 kB)                                         
#>  Got scales 1.2.1 (source) (270.61 kB)                                         
#>  Got mgcv 1.8-40 (source) (1.18 MB)                                            
#>  Got rlang 1.0.5 (source) (741.68 kB)                                          
#>  Got pillar 1.8.1 (source) (479.98 kB)                                         
#>  Got tibble 3.1.8 (source) (672.34 kB)                                         
#>  Got Matrix 1.4-1 (source) (2.86 MB)                                           
#>  Got utf8 1.2.2 (source) (240.33 kB)                                           
#>  Got withr 2.5.0 (source) (102.09 kB)                                          
#>  Got lattice 0.20-45 (source) (399.47 kB)                                      
#>  Got vctrs 0.4.1 (source) (916.78 kB)                                          
#>  Got MASS 7.3-58.1 (source) (514.88 kB)                                        
#>  Got viridisLite 0.4.1 (source) (1.27 MB)                                      
#>  Got fansi 1.0.3 (source) (481.16 kB)                                          
#>  Got mgcv 1.8-40 (source) (1.18 MB)                                            
#>  Got nlme 3.1-159 (source) (846.86 kB)                                         
#>  Got lattice 0.20-45 (source) (399.47 kB)                                      
#>  Got farver 2.1.1 (source) (1.27 MB)                                           
#>  Got isoband 0.2.5 (source) (1.67 MB)                                          
#>  Got ggplot2 3.3.6 (source) (3.06 MB)                                          
#>  Got Matrix 1.4-1 (source) (2.86 MB)                                           
#> # A data frame: 34 × 35                                                         
#>    ref       type  direct direc…¹ status package version license needs…² prior…³
#>    <chr>     <chr> <lgl>  <lgl>   <chr>  <chr>   <chr>   <chr>   <lgl>   <chr>  
#>  1 cli       stan… FALSE  FALSE   OK     cli     3.4.0   MIT + … TRUE    NA     
#>  2 colorspa… stan… FALSE  FALSE   OK     colors… 2.0-3   BSD_3_… TRUE    NA     
#>  3 digest    stan… FALSE  FALSE   OK     digest  0.6.29  GPL (>… TRUE    NA     
#>  4 fansi     stan… FALSE  FALSE   OK     fansi   1.0.3   GPL-2 … TRUE    NA     
#>  5 farver    stan… FALSE  FALSE   OK     farver  2.1.1   MIT + … TRUE    NA     
#>  6 ggplot2   stan… TRUE   TRUE    OK     ggplot2 3.3.6   MIT + … FALSE   NA     
#>  7 glue      stan… FALSE  FALSE   OK     glue    1.6.2   MIT + … TRUE    NA     
#>  8 gtable    stan… FALSE  FALSE   OK     gtable  0.3.1   MIT + … FALSE   NA     
#>  9 isoband   stan… FALSE  FALSE   OK     isoband 0.2.5   MIT + … TRUE    NA     
#> 10 labeling  stan… FALSE  FALSE   OK     labeli… 0.4.2   MIT + … FALSE   NA     
#> # … with 24 more rows, 25 more variables: md5sum <chr>, sha256 <chr>,           
#> #   filesize <int>, built <chr>, platform <chr>, rversion <chr>,                
#> #   repotype <chr>, repodir <chr>, target <chr>, deps <list>, mirror <chr>,     
#> #   sources <list>, remote <list>, error <list>, metadata <list>, extra <list>, 
#> #   dep_types <list>, params <list>, sysreqs <chr>, cache_status <chr>,         
#> #   fulltarget <chr>, fulltarget_tree <chr>, download_status <chr>,             
#> #   download_error <list>, file_size <dbl>, and abbreviated variable names …    
#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable 
#> names                                                                           
#> [1] "src"                                                                       

Installation

How to install a package into a new library?

library(pkgdepends)
dir.create(new_lib <- tempfile())
prop <- new_pkg_installation_proposal("pkgconfig", config = list(library = new_lib))
prop$solve()
prop$download()
prop$install()
lib_status(new_lib)
#>  No downloads are needed, 1 pkg (6.08 kB) is cached                            
#>  Building pkgconfig 2.0.3                                                      
#>  Built pkgconfig 2.0.3 (1s)                                                    
#>  Installed pkgconfig 2.0.3  (37ms)                                             
#>  Summary:   1 new  in 1s                                                       
#> # A data frame: 1 × 31                                                          
#>   library    package title version license imports sugge…¹ needs…² repos…³ built
#>   <chr>      <chr>   <chr> <chr>   <chr>   <chr>   <chr>   <lgl>   <chr>   <chr>
#> 1 /tmp/Rtmp… pkgcon… Priv… 2.0.3   MIT + … utils   covr, … FALSE   CRAN    R 4.…
#> # … with 21 more variables: remotetype <chr>, remotepkgref <chr>,               
#> #   remoteref <chr>, remoterepos <chr>, remotepkgplatform <chr>,                
#> #   remotesha <chr>, depends <chr>, linkingto <chr>, enhances <chr>,            
#> #   md5sum <chr>, platform <chr>, priority <chr>, biocviews <chr>,              
#> #   sysreqs <chr>, ref <chr>, type <chr>, status <chr>, rversion <chr>,         
#> #   sources <list>, repotype <chr>, deps <list>, and abbreviated variable names 
#> #   ¹​suggests, ²​needscompilation, ³​repository                                
#> # ℹ Use `colnames()` to see all variable names                                  

How to update a package?

Install an older version first.

library(pkgdepends)
dir.create(new_lib <- tempfile())
config <- list(library = new_lib)
prop <- new_pkg_installation_proposal("cran/pkgconfig@2.0.2", config = config)
prop$solve()
prop$download()
prop$install()
lib_status(new_lib)
#>  No downloads are needed, 1 pkg is cached                                      
#>  Got pkgconfig 2.0.2 (source) (13.22 kB)                                       
#>  Packaging pkgconfig 2.0.2                                                     
#>  Packaged pkgconfig 2.0.2 (310ms)                                              
#>  Building pkgconfig 2.0.2                                                      
#>  Built pkgconfig 2.0.2 (923ms)                                                 
#>  Installed pkgconfig 2.0.2 (github::cran/pkgconfig@d892880) (20ms)             
#>  Summary:   1 new  in 942ms                                                    
#> # A data frame: 1 × 32                                                          
#>   library    package title version license imports sugge…¹ needs…² repos…³ built
#>   <chr>      <chr>   <chr> <chr>   <chr>   <chr>   <chr>   <lgl>   <chr>   <chr>
#> 1 /tmp/Rtmp… pkgcon… Priv… 2.0.2   MIT + … utils   covr, … FALSE   CRAN    R 4.…
#> # … with 22 more variables: remotetype <chr>, remotehost <chr>,                 
#> #   remoterepo <chr>, remoteusername <chr>, remotepkgref <chr>,                 
#> #   remoteref <chr>, remotesha <chr>, depends <chr>, linkingto <chr>,           
#> #   enhances <chr>, md5sum <chr>, platform <chr>, priority <chr>,               
#> #   biocviews <chr>, sysreqs <chr>, ref <chr>, type <chr>, status <chr>,        
#> #   rversion <chr>, sources <list>, repotype <chr>, deps <list>, and            
#> #   abbreviated variable names ¹​suggests, ²​needscompilation, ³​repository     
#> # ℹ Use `colnames()` to see all variable names                                  

Now update.

library(pkgdepends)
prop2 <- new_pkg_installation_proposal("pkgconfig", config = config)
prop2$set_solve_policy("upgrade")
prop2$solve()
prop2$download()
prop2$install()
lib_status(new_lib)
#>  No downloads are needed, 1 pkg (6.08 kB) is cached                            
#>  Building pkgconfig 2.0.3                                                      
#>  Built pkgconfig 2.0.3 (961ms)                                                 
#>  Installed pkgconfig 2.0.3  (25ms)                                             
#>  Summary:   1 updated  in 985ms                                                
#> # A data frame: 1 × 31                                                          
#>   library    package title version license imports sugge…¹ needs…² repos…³ built
#>   <chr>      <chr>   <chr> <chr>   <chr>   <chr>   <chr>   <lgl>   <chr>   <chr>
#> 1 /tmp/Rtmp… pkgcon… Priv… 2.0.3   MIT + … utils   covr, … FALSE   CRAN    R 4.…
#> # … with 21 more variables: remotetype <chr>, remotepkgref <chr>,               
#> #   remoteref <chr>, remoterepos <chr>, remotepkgplatform <chr>,                
#> #   remotesha <chr>, depends <chr>, linkingto <chr>, enhances <chr>,            
#> #   md5sum <chr>, platform <chr>, priority <chr>, biocviews <chr>,              
#> #   sysreqs <chr>, ref <chr>, type <chr>, status <chr>, rversion <chr>,         
#> #   sources <list>, repotype <chr>, deps <list>, and abbreviated variable names 
#> #   ¹​suggests, ²​needscompilation, ³​repository                                
#> # ℹ Use `colnames()` to see all variable names