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
#>  Loading metadata database ... done                                            
#> # A data frame: 28 × 37                                                         
#>    ref    type  direct directpkg status package version license needscompilation
#>    <chr>  <chr> <lgl>  <lgl>     <chr>  <chr>   <chr>   <chr>   <lgl>           
#>  1 cli    stan… FALSE  FALSE     OK     cli     3.6.1   MIT + … TRUE            
#>  2 color… stan… FALSE  FALSE     OK     colors… 2.1-0   BSD_3_… TRUE            
#>  3 fansi  stan… FALSE  FALSE     OK     fansi   1.0.6   GPL-2 … TRUE            
#>  4 farver stan… FALSE  FALSE     OK     farver  2.1.1   MIT + … TRUE            
#>  5 ggplo… stan… TRUE   TRUE      OK     ggplot2 3.4.4   MIT + … FALSE           
#>  6 glue   stan… FALSE  FALSE     OK     glue    1.6.2   MIT + … TRUE            
#>  7 gtable stan… FALSE  FALSE     OK     gtable  0.3.4   MIT + … FALSE           
#>  8 isoba… stan… FALSE  FALSE     OK     isoband 0.2.7   MIT + … TRUE            
#>  9 label… stan… FALSE  FALSE     OK     labeli… 0.4.3   MIT + … FALSE           
#> 10 lifec… stan… FALSE  FALSE     OK     lifecy… 1.0.4   MIT + … FALSE           
#> # ℹ 18 more rows                                                                
#> # ℹ 28 more variables: priority <chr>, 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>,         
#> #   sysreqs_packages <list>, sysreqs_pre_install <chr>, …                       
#> # ℹ Use `print(n = ...)` to see more rows                                       

You can also draw a dependency tree:

prop$draw()
#> ggplot2 3.4.4 [new][bld][dl] (3.16 MB)                                          
#> ├─cli 3.6.1 [new][bld][cmp]                                                     
#> ├─glue 1.6.2 [new][bld][cmp]                                                    
#> ├─gtable 0.3.4 [new][bld][dl] (130.10 kB)                                       
#> │ ├─cli                                                                         
#> │ ├─glue                                                                        
#> │ ├─lifecycle 1.0.4 [new][bld][dl] (107.66 kB)                                  
#> │ │ ├─cli                                                                       
#> │ │ ├─glue                                                                      
#> │ │ └─rlang 1.1.2 [new][bld][cmp]                                               
#> │ └─rlang                                                                       
#> ├─isoband 0.2.7 [new][bld][cmp][dl] (1.59 MB)                                   
#> ├─lifecycle                                                                     
#> ├─MASS 7.3-60 < 7.3-60.1 [old]                                                  
#> ├─mgcv 1.9-0                                                                    
#> │ ├─nlme 3.1-163 < 3.1-164 [old]                                                
#> │ │ └─lattice 0.21-9 < 0.22-5 [old]                                             
#> │ └─Matrix 1.6-1.1 < 1.6-4 [old]                                                
#> │   └─lattice                                                                   
#> ├─rlang                                                                         
#> ├─scales 1.3.0 [new][bld][cmp][dl] (302.54 kB)                                  
#> │ ├─cli                                                                         
#> │ ├─farver 2.1.1 [new][bld][cmp][dl] (1.27 MB)                                  
#> │ ├─glue                                                                        
#> │ ├─labeling 0.4.3 [new][bld][dl] (10.17 kB)                                    
#> │ ├─lifecycle                                                                   
#> │ ├─munsell 0.5.0 [new][bld][dl] (182.65 kB)                                    
#> │ │ └─colorspace 2.1-0 [new][bld][cmp][dl] (2.12 MB)                            
#> │ ├─R6 2.5.1 [new][bld]                                                         
#> │ ├─RColorBrewer 1.1-3 [new][bld][dl] (11.64 kB)                                
#> │ ├─rlang                                                                       
#> │ └─viridisLite 0.4.2 [new][bld][dl] (1.27 MB)                                  
#> ├─tibble 3.2.1 [new][bld][cmp][dl] (565.98 kB)                                  
#> │ ├─fansi 1.0.6 [new][bld][cmp][dl] (482.48 kB)                                 
#> │ ├─lifecycle                                                                   
#> │ ├─magrittr 2.0.3 [new][bld][cmp][dl] (267.07 kB)                              
#> │ ├─pillar 1.9.0 [new][bld][dl] (444.53 kB)                                     
#> │ │ ├─cli                                                                       
#> │ │ ├─fansi                                                                     
#> │ │ ├─glue                                                                      
#> │ │ ├─lifecycle                                                                 
#> │ │ ├─rlang                                                                     
#> │ │ ├─utf8 1.2.4 [new][bld][cmp][dl] (241.08 kB)                                
#> │ │ └─vctrs 0.6.5 [new][bld][cmp][dl] (969.07 kB)                               
#> │ │   ├─cli                                                                     
#> │ │   ├─glue                                                                    
#> │ │   ├─lifecycle                                                               
#> │ │   └─rlang                                                                   
#> │ ├─pkgconfig 2.0.3 [new][bld][dl] (6.08 kB)                                    
#> │ ├─rlang                                                                       
#> │ └─vctrs                                                                       
#> ├─vctrs                                                                         
#> └─withr 2.5.2 [new][bld]                                                        
#>                                                                                 
#> Key:  [new] new | [old] outdated | [dl] download | [bld] build | [cmp] compile  

How to list all dependencies of a GitHub package?

library(pkgdepends)
prop <- new_pkg_deps("tidyverse/ggplot2")
prop$solve()
prop$get_solution()$data
#> # A data frame: 28 × 37                                                         
#>    ref    type  direct directpkg status package version license needscompilation
#>    <chr>  <chr> <lgl>  <lgl>     <chr>  <chr>   <chr>   <chr>   <lgl>           
#>  1 tidyv… gith… TRUE   TRUE      OK     ggplot2 3.4.4.… MIT + … TRUE            
#>  2 cli    stan… FALSE  FALSE     OK     cli     3.6.1   MIT + … TRUE            
#>  3 color… stan… FALSE  FALSE     OK     colors… 2.1-0   BSD_3_… TRUE            
#>  4 fansi  stan… FALSE  FALSE     OK     fansi   1.0.6   GPL-2 … TRUE            
#>  5 farver stan… FALSE  FALSE     OK     farver  2.1.1   MIT + … TRUE            
#>  6 glue   stan… FALSE  FALSE     OK     glue    1.6.2   MIT + … TRUE            
#>  7 gtable stan… FALSE  FALSE     OK     gtable  0.3.4   MIT + … FALSE           
#>  8 isoba… stan… FALSE  FALSE     OK     isoband 0.2.7   MIT + … TRUE            
#>  9 label… stan… FALSE  FALSE     OK     labeli… 0.4.3   MIT + … FALSE           
#> 10 lifec… stan… FALSE  FALSE     OK     lifecy… 1.0.4   MIT + … FALSE           
#> # ℹ 18 more rows                                                                
#> # ℹ 28 more variables: priority <chr>, 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>,         
#> #   sysreqs_packages <list>, sysreqs_pre_install <chr>, …                       
#> # ℹ Use `print(n = ...)` to see more rows                                       

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: 14 × 37                                                         
#>    ref    type  direct directpkg status package version license needscompilation
#>    <chr>  <chr> <lgl>  <lgl>     <chr>  <chr>   <chr>   <chr>   <lgl>           
#>  1 local… local TRUE   TRUE      OK     pkgdep… 0.7.1   MIT + … NA              
#>  2 callr  stan… FALSE  FALSE     OK     callr   3.7.3   MIT + … FALSE           
#>  3 cli    stan… FALSE  FALSE     OK     cli     3.6.1   MIT + … TRUE            
#>  4 curl   stan… FALSE  FALSE     OK     curl    5.2.0   MIT + … TRUE            
#>  5 desc   stan… FALSE  FALSE     OK     desc    1.4.3   MIT + … FALSE           
#>  6 filel… stan… FALSE  FALSE     OK     filelo… 1.0.2   MIT + … TRUE            
#>  7 jsonl… stan… FALSE  FALSE     OK     jsonli… 1.8.8   MIT + … TRUE            
#>  8 lpSol… stan… FALSE  FALSE     OK     lpSolve 5.6.20  LGPL-2  TRUE            
#>  9 pkgbu… stan… FALSE  FALSE     OK     pkgbui… 1.4.3   MIT + … FALSE           
#> 10 pkgca… stan… FALSE  FALSE     OK     pkgcac… 2.2.1   MIT + … TRUE            
#> 11 proce… stan… FALSE  FALSE     OK     proces… 3.8.3   MIT + … TRUE            
#> 12 ps     stan… FALSE  FALSE     OK     ps      1.7.5   MIT + … TRUE            
#> 13 R6     stan… FALSE  FALSE     OK     R6      2.5.1   MIT + … FALSE           
#> 14 zip    stan… FALSE  FALSE     OK     zip     2.3.0   MIT + … TRUE            
#> # ℹ 28 more variables: priority <chr>, 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>,         
#> #   sysreqs_packages <list>, sysreqs_pre_install <chr>,                         
#> #   sysreqs_post_install <chr>, sysreqs_install <chr>, lib_status <chr>, …      

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)
#>  Getting 28 pkgs (25.09 MB), 5 (1.60 MB) cached                                
#>  Got labeling 0.4.3 (source) (10.17 kB)                                        
#>  Got fansi 1.0.6 (source) (482.48 kB)                                          
#>  Got tibble 3.2.1 (source) (565.98 kB)                                         
#>  Got nlme 3.1-164 (source) (836.83 kB)                                         
#>  Got farver 2.1.1 (source) (1.27 MB)                                           
#>  Got mgcv 1.9-0 (source) (1.11 MB)                                             
#>  Got lifecycle 1.0.4 (source) (107.66 kB)                                      
#>  Got MASS 7.3-60.1 (source) (535.22 kB)                                        
#>  Got pkgconfig 2.0.3 (source) (6.08 kB)                                        
#>  Got munsell 0.5.0 (source) (182.65 kB)                                        
#>  Got lattice 0.22-5 (source) (599.04 kB)                                       
#>  Got scales 1.3.0 (source) (302.54 kB)                                         
#>  Got viridisLite 0.4.2 (source) (1.27 MB)                                      
#>  Got utf8 1.2.4 (source) (241.08 kB)                                           
#>  Got colorspace 2.1-0 (source) (2.12 MB)                                       
#>  Got RColorBrewer 1.1-3 (source) (11.64 kB)                                    
#>  Got gtable 0.3.4 (source) (130.10 kB)                                         
#>  Got mgcv 1.9-0 (source) (1.11 MB)                                             
#>  Got MASS 7.3-60 (source) (561.53 kB)                                          
#>  Got lattice 0.22-5 (source) (599.04 kB)                                       
#>  Got isoband 0.2.7 (source) (1.59 MB)                                          
#>  Got magrittr 2.0.3 (source) (267.07 kB)                                       
#>  Got ggplot2 3.4.4 (source) (3.16 MB)                                          
#>  Got pillar 1.9.0 (source) (444.53 kB)                                         
#>  Got vctrs 0.6.5 (source) (969.07 kB)                                          
#>  Got nlme 3.1-164 (source) (836.83 kB)                                         
#>  Got Matrix 1.6-4 (source) (2.88 MB)                                           
#>  Got Matrix 1.6-4 (source) (2.88 MB)                                           
#> # A data frame: 33 × 39                                                         
#>    ref    type  direct directpkg status package version license needscompilation
#>    <chr>  <chr> <lgl>  <lgl>     <chr>  <chr>   <chr>   <chr>   <lgl>           
#>  1 cli    stan… FALSE  FALSE     OK     cli     3.6.1   MIT + … TRUE            
#>  2 color… stan… FALSE  FALSE     OK     colors… 2.1-0   BSD_3_… TRUE            
#>  3 fansi  stan… FALSE  FALSE     OK     fansi   1.0.6   GPL-2 … TRUE            
#>  4 farver stan… FALSE  FALSE     OK     farver  2.1.1   MIT + … TRUE            
#>  5 ggplo… stan… TRUE   TRUE      OK     ggplot2 3.4.4   MIT + … FALSE           
#>  6 glue   stan… FALSE  FALSE     OK     glue    1.6.2   MIT + … TRUE            
#>  7 gtable stan… FALSE  FALSE     OK     gtable  0.3.4   MIT + … FALSE           
#>  8 isoba… stan… FALSE  FALSE     OK     isoband 0.2.7   MIT + … TRUE            
#>  9 label… stan… FALSE  FALSE     OK     labeli… 0.4.3   MIT + … FALSE           
#> 10 latti… stan… FALSE  FALSE     OK     lattice 0.22-5  GPL (>… TRUE            
#> # ℹ 23 more rows                                                                
#> # ℹ 30 more variables: priority <chr>, 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>,         
#> #   sysreqs_packages <list>, sysreqs_pre_install <chr>, …                       
#> # ℹ Use `print(n = ...)` to see more rows                                       
#> [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 (874ms)                                                 
#>  Installed pkgconfig 2.0.3  (1s)                                               
#>  Summary:   1 new  in 1.9s                                                     
#> # A data frame: 1 × 31                                                          
#>   library        package title version license imports suggests needscompilation
#>   <chr>          <chr>   <chr> <chr>   <chr>   <chr>   <chr>    <lgl>           
#> 1 /tmp/RtmpdpZU… pkgcon… Priv… 2.0.3   MIT + … utils   covr, t… FALSE           
#> # ℹ 23 more variables: repository <chr>, built <chr>, 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>                 

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 (287ms)                                              
#>  Building pkgconfig 2.0.2                                                      
#>  Built pkgconfig 2.0.2 (865ms)                                                 
#>  Installed pkgconfig 2.0.2 (github::cran/pkgconfig@d892880) (1s)               
#>  Summary:   1 new  in 1.9s                                                     
#> # A data frame: 1 × 32                                                          
#>   library        package title version license imports suggests needscompilation
#>   <chr>          <chr>   <chr> <chr>   <chr>   <chr>   <chr>    <lgl>           
#> 1 /tmp/RtmpdpZU… pkgcon… Priv… 2.0.2   MIT + … utils   covr, t… FALSE           
#> # ℹ 24 more variables: repository <chr>, built <chr>, 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>   

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 (871ms)                                                 
#>  Installed pkgconfig 2.0.3  (1s)                                               
#>  Summary:   1 updated  in 1.9s                                                 
#> # A data frame: 1 × 31                                                          
#>   library        package title version license imports suggests needscompilation
#>   <chr>          <chr>   <chr> <chr>   <chr>   <chr>   <chr>    <lgl>           
#> 1 /tmp/RtmpdpZU… pkgcon… Priv… 2.0.3   MIT + … utils   covr, t… FALSE           
#> # ℹ 23 more variables: repository <chr>, built <chr>, 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>