1- find_root <- function () {
2- if (! requireNamespace(" rprojroot" , quietly = TRUE )) {
3- install.packages(" rprojroot" , lib = lib , repos = repos )
1+ install_required_packages <- function (lib = NULL , repos = getOption(" repos" )) {
2+
3+ if (is.null(lib )) {
4+ lib <- .libPaths()
45 }
56
7+ message(" lib paths: " , paste(lib , collapse = " , " ))
8+ missing_pkgs <- setdiff(
9+ c(" rprojroot" , " desc" , " remotes" , " renv" ),
10+ rownames(installed.packages(lib.loc = lib ))
11+ )
12+
13+ install.packages(missing_pkgs , lib = lib , repos = repos )
14+
15+ }
16+
17+ find_root <- function () {
18+
619 cfg <- rprojroot :: has_file_pattern(" ^_config.y*ml$" )
720 root <- rprojroot :: find_root(cfg )
821
922 root
1023}
1124
12- identify_dependencies <- function (lib = NULL , repos = getOption(" repos" )) {
13-
14- if (is.null(lib )) {
15- lib <- .libPaths()
16- }
17-
18- if (! requireNamespace(" renv" , quietly = TRUE )) {
19- install.packages(" renv" , lib = lib , repos = repos )
20- }
25+ identify_dependencies <- function () {
2126
2227 root <- find_root()
2328
@@ -31,38 +36,20 @@ identify_dependencies <- function(lib = NULL, repos = getOption("repos")) {
3136 required_pkgs
3237}
3338
34- install_dependencies <- function (required_pkgs ,
35- lib = NULL , repos = getOption(" repos" ),
36- update = FALSE , ... ) {
37-
38- if (missing(lib )) {
39- lib <- .libPaths()
40- }
39+ create_description <- function (required_pkgs ) {
40+ d <- desc :: description $ new(" !new" )
41+ lapply(required_pkgs , function (x ) d $ set_dep(x ))
42+ d $ write(" DESCRIPTION" )
43+ }
4144
42- missing_pkgs <- setdiff (required_pkgs , rownames(installed.packages()))
45+ install_dependencies <- function (required_pkgs , ... ) {
4346
44- if (length(missing_pkgs )) {
45- message(" Installing missing required packages: " ,
46- paste(missing_pkgs , collapse = " , " ))
47- install.packages(missing_pkgs , lib = lib , repos = repos )
48- }
49-
50- if (update ) {
51- update.packages(
52- lib.loc = lib , repos = repos ,
53- ask = FALSE , checkBuilt = TRUE , ...
54- )
55- }
47+ create_description(required_pkgs )
48+ on.exit(file.remove(" DESCRIPTION" ))
49+ remotes :: install_deps(dependencies = TRUE , ... )
5650
5751 if (require(" knitr" ) && packageVersion(" knitr" ) < ' 1.9.19' ) {
5852 stop(" knitr must be version 1.9.20 or higher" )
5953 }
6054
6155}
62-
63- create_description <- function (required_pkgs ) {
64- require(" desc" )
65- d <- description $ new(" !new" )
66- lapply(required_pkgs , function (x ) d $ set_dep(x ))
67- d $ write(" DESCRIPTION" )
68- }
0 commit comments