pkg_install: Install packages

View source: R/package.R

pkg_installR Documentation

Install packages

Description

Install one or more packages and their dependencies into a single package library.

Usage

pkg_install(
  pkg,
  lib = .libPaths()[[1L]],
  upgrade = FALSE,
  ask = interactive(),
  dependencies = NA
)

Arguments

pkg

Package names or package references. E.g.

  • ggplot2: package from CRAN, Bioconductor or a CRAN-like repository in general,

  • tidyverse/ggplot2: package from GitHub,

  • tidyverse/ggplot2@v3.4.0: package from GitHub tag or branch,

  • ⁠https://examples.com/.../ggplot2_3.3.6.tar.gz⁠: package from URL,

  • .: package in the current working directory.

See "Package sources" for more details.

lib

Package library to install the packages to. Note that all dependent packages will be installed here, even if they are already installed in another library. The only exceptions are base and recommended packages installed in .Library. These are not duplicated in lib, unless a newer version of a recommemded package is needed.

upgrade

When FALSE, the default, pak does the minimum amount of work to give you the latest version(s) of pkg. It will only upgrade dependent packages if pkg, or one of their dependencies explicitly require a higher version than what you currently have. It will also prefer a binary package over to source package, even it the binary package is older.

When upgrade = TRUE, pak will ensure that you have the latest version(s) of pkg and all their dependencies.

ask

Whether to ask for confirmation when installing a different version of a package that is already installed. Installations that only add new packages never require confirmation.

dependencies

What kinds of dependencies to install. Most commonly one of the following values:

  • NA: only required (hard) dependencies,

  • TRUE: required dependencies plus optional and development dependencies,

  • FALSE: do not install any dependencies. (You might end up with a non-working package, and/or the installation might fail.) See Package dependency types for other possible values and more information about package dependencies.

Value

(Invisibly) A data frame with information about the installed package(s).

Examples

pkg_install("dplyr")
#>                                                                         
#> → Will install 5 packages.                                              
#> → All 5 packages (2.14 MB) are cached.                                  
#> + dplyr        1.0.9                                                    
#> + generics     0.1.2                                                    
#> + purrr        0.3.4                                                    
#> + R6           2.5.1                                                    
#> + tidyselect   1.1.2                                                    
#>  No downloads are needed, 5 pkgs (2.14 MB) are cached                  
#>  Got R6 2.5.1 (aarch64-apple-darwin20) (82.52 kB)                      
#>  Installed R6 2.5.1  (43ms)                                            
#>  Installed generics 0.1.2  (62ms)                                      
#>  Installed dplyr 1.0.9  (88ms)                                         
#>  Installed purrr 0.3.4  (88ms)                                         
#>  Installed tidyselect 1.1.2  (94ms)                                    
#>  1 pkg + 17 deps: kept 12, added 5, dld 1 (82.52 kB) [1.2s]            

Upgrade dplyr and all its dependencies:

pkg_install("dplyr", upgrade = TRUE)
#>                                                                         
#> → Will update 1 package.                                                
#> → The package (742.51 kB) is cached.                                    
#> + rlang 1.0.2 → 1.0.3 👷🏿‍♀️🔧                                            
#>  No downloads are needed, 1 pkg (742.51 kB) is cached                  
#>  Building rlang 1.0.3                                                  
#>  Built rlang 1.0.3 (5.8s)                                              
#>  Installed rlang 1.0.3  (32ms)                                         
#>  1 pkg + 17 deps: kept 17, upd 1 [6.3s]                                

Install the development version of dplyr:

pkg_install("tidyverse/dplyr")
#>  Loading metadata database ... done                                    
#>                                                                         
#> → Will install 16 packages.                                             
#> → All 16 packages (8.09 MB) are cached.                                 
#> + cli          3.4.1                                                    
#> + dplyr        1.0.99.9000 👷🏾‍♂️🔧 (GitHub: e6252f8)                     
#> + fansi        1.0.3                                                    
#> + generics     0.1.3                                                    
#> + glue         1.6.2                                                    
#> + lifecycle    1.0.3                                                    
#> + magrittr     2.0.3                                                    
#> + pillar       1.8.1                                                    
#> + pkgconfig    2.0.3                                                    
#> + R6           2.5.1                                                    
#> + rlang        1.0.6                                                    
#> + tibble       3.1.8                                                    
#> + tidyselect   1.2.0                                                    
#> + utf8         1.2.2                                                    
#> + vctrs        0.5.1                                                    
#> + withr        2.5.0                                                    
#>  No downloads are needed, 16 pkgs (8.09 MB) are cached                 
#>  Installed R6 2.5.1  (58ms)                                            
#>  Installed cli 3.4.1  (69ms)                                           
#>  Installed fansi 1.0.3  (92ms)                                         
#>  Installed generics 0.1.3  (99ms)                                      
#>  Installed glue 1.6.2  (108ms)                                         
#>  Installed lifecycle 1.0.3  (144ms)                                    
#>  Installed magrittr 2.0.3  (152ms)                                     
#>  Installed pillar 1.8.1  (160ms)                                       
#>  Installed pkgconfig 2.0.3  (63ms)                                     
#>  Installed rlang 1.0.6  (37ms)                                         
#>  Installed tibble 3.1.8  (41ms)                                        
#>  Installed tidyselect 1.2.0  (38ms)                                    
#>  Installed utf8 1.2.2  (36ms)                                          
#>  Installed vctrs 0.5.1  (39ms)                                         
#>  Installed withr 2.5.0  (30ms)                                         
#>  Packaging dplyr 1.0.99.9000                                           
#>  Packaged dplyr 1.0.99.9000 (8.3s)                                     
#>  Building dplyr 1.0.99.9000                                            
#>  Built dplyr 1.0.99.9000 (5.2s)                                        
#>  Installed dplyr 1.0.99.9000 (github::tidyverse/dplyr@e6252f8) (24ms)  
#>  1 pkg + 15 deps: added 16 [18.9s]                                     

Switch back to the CRAN version. This will be fast because pak will have cached the prior install.

pkg_install("dplyr")
#>  Updated metadata database: 2.43 MB in 6 files.                        
#>  Updating metadata database ... done                                   
#>                                                                         
#> → Will install 16 packages.                                             
#> → All 16 packages (9.42 MB) are cached.                                 
#> + cli          3.4.1                                                    
#> + dplyr        1.0.10                                                   
#> + fansi        1.0.3                                                    
#> + generics     0.1.3                                                    
#> + glue         1.6.2                                                    
#> + lifecycle    1.0.3                                                    
#> + magrittr     2.0.3                                                    
#> + pillar       1.8.1                                                    
#> + pkgconfig    2.0.3                                                    
#> + R6           2.5.1                                                    
#> + rlang        1.0.6                                                    
#> + tibble       3.1.8                                                    
#> + tidyselect   1.2.0                                                    
#> + utf8         1.2.2                                                    
#> + vctrs        0.5.1                                                    
#> + withr        2.5.0                                                    
#>  No downloads are needed, 16 pkgs (9.42 MB) are cached                 
#>  Installed R6 2.5.1  (66ms)                                            
#>  Installed cli 3.4.1  (76ms)                                           
#>  Installed dplyr 1.0.10  (111ms)                                       
#>  Installed fansi 1.0.3  (119ms)                                        
#>  Installed generics 0.1.3  (125ms)                                     
#>  Installed glue 1.6.2  (132ms)                                         
#>  Installed lifecycle 1.0.3  (149ms)                                    
#>  Installed magrittr 2.0.3  (162ms)                                     
#>  Installed pillar 1.8.1  (56ms)                                        
#>  Installed pkgconfig 2.0.3  (35ms)                                     
#>  Installed rlang 1.0.6  (57ms)                                         
#>  Installed tibble 3.1.8  (41ms)                                        
#>  Installed tidyselect 1.2.0  (40ms)                                    
#>  Installed utf8 1.2.2  (37ms)                                          
#>  Installed vctrs 0.5.1  (39ms)                                         
#>  Installed withr 2.5.0  (31ms)                                         
#>  1 pkg + 15 deps: added 16 [7.2s]                                      

See Also

Get started with pak, Package sources, FAQ, The dependency solver.

Other package functions: lib_status(), pak(), pkg_deps_tree(), pkg_deps(), pkg_download(), pkg_remove(), pkg_status(), pkg_sysreqs()


r-lib/pak documentation built on April 10, 2024, 8:23 p.m.