Skip to content

Instantly share code, notes, and snippets.

@alex-gable
Last active September 8, 2021 07:09
Show Gist options
  • Save alex-gable/d18eef6081b0896ffadbc5450ded0345 to your computer and use it in GitHub Desktop.
Save alex-gable/d18eef6081b0896ffadbc5450ded0345 to your computer and use it in GitHub Desktop.
update function that works with pak
update_pak <- function() {
`%>%` <- magrittr::`%>%`
pl <- pak::lib_status() %>%
dplyr::mutate(package_full =
dplyr::case_when(
dplyr::coalesce(repository, remotetype) == "CRAN" ~ package,
dplyr::coalesce(repository, remotetype) == "github" ~
paste0(remoteusername, "/", remoterepo),
TRUE ~ NA_character_)) %>%
dplyr::filter(!is.na(package_full))
ap <- tibble::as_tibble(utils::available.packages())
cran_plu <- pl %>%
dplyr::filter(repository == "CRAN") %>%
dplyr::inner_join(ap, by = c(package = "Package")) %>%
dplyr::filter(version < Version) %>%
dplyr::pull(package)
gh_plu <- pl %>%
dplyr::filter(dplyr::coalesce(repository, remotetype) == "github") %>%
dplyr::pull(package_full)
pak::pkg_install(cran_plu, upgrade = TRUE)
pak::pkg_install(gh_plu, upgrade = TRUE)
}
@alex-gable
Copy link
Author

fails if a build fails, doesn't exit properly if nothing to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment