get_recursive_pkg_dependencies <-
function(pkgs,
library_path = .libPaths(),
dbg = TRUE) {
pkgs_installed <-
pkgs[pkgs %in% rownames(installed.packages(lib.loc = library_path))]
setNames(lapply(pkgs_installed, function(pkg) {
kwb.utils::catAndRun(
sprintf("Getting recursive dependencies for '%s'", pkg),
expr = {
packrat:::recursivePackageDependencies(pkg,
lib.loc = library_path)
},
dbg = dbg
)
}),
nm = pkgs_installed)
}
get_pkg_dependencies <-
function(pkgs,
library_path = .libPaths(),
dbg = TRUE) {
pkgs_installed <-
pkgs[pkgs %in% rownames(installed.packages(lib.loc = library_path))]
setNames(lapply(pkgs_installed, function(pkg) {
kwb.utils::catAndRun(
sprintf("Getting dependencies for '%s'", pkg),
expr = {
packrat:::getPackageDependencies(pkg, lib.loc = library_path)
},
dbg = dbg
)
}),
nm = pkgs_installed)
}
###############################################################################
### Define Function for Installing KWB-R GitHub Packages
###############################################################################
install_kwb_github_packages <- function(pkgs_kwb,
dependencies = TRUE,
...) {
pkgs_kwb_github <- sprintf("KWB-R/%s", pkgs_kwb)
sapply(
pkgs_kwb_github,
FUN = function(gh_repo) {
try(remotes::install_github(repo = gh_repo,
dependencies = dependencies,
...))
}
)
}
###############################################################################
### Use the Install Function For KWB-R Packages
###############################################################################
pkgs <- pkgmeta::get_github_packages()
install_kwb_github_packages(pkgs_kwb = pkgs$name, upgrade = "always")
pkgs_recursive_dependencies <- get_recursive_pkg_dependencies(pkgs$name)
pkgs_dependencies <- get_pkg_dependencies(pkgs$name)
deps_df <- tibble::tibble(package = names(total_deps_per_pkg),
n_dependencies = sapply(pkgs_dependencies, length),
n_recursive_dependencies = sapply(pkgs_recursive_dependencies, length)) %>%
dplyr::arrange(dplyr::desc(n_recursive_dependencies))
Using this locally with GITHUB_PAT with private KWB-R repo scope (installation failed for 2 private repos, see #2), these are the total (recursive) dependencies: