Skip to content

Instantly share code, notes, and snippets.

@StaffanBetner
Last active September 28, 2023 12:12
Show Gist options
  • Save StaffanBetner/d632bd70686aebd8e488bdc1a454c8e2 to your computer and use it in GitHub Desktop.
Save StaffanBetner/d632bd70686aebd8e488bdc1a454c8e2 to your computer and use it in GitHub Desktop.
if(!("pak" %in% as.data.frame(installed.packages())$Package)){install.packages("pak")}
require(pak)
pkg_load <- function(...) {
if(!("pak" %in% as.data.frame(installed.packages())$Package)){install.packages("pak")}
pack <- sapply(match.call(), as.character)[-1]
pack[!(pack %in% as.data.frame(installed.packages())$Package)] -> to_install
if(length(to_install) > 0) pak(to_install) else ""
lapply(X = pack, FUN = function(x){tryCatch(require(x, character.only = T), error = function(e){NULL})}) -> X
}
pkg_update <- function(...){pkg_install(rownames(old.packages(checkBuilt = TRUE)), upgrade = TRUE, ask = FALSE)}
#if (interactive() && getRversion() >= "4.0.0") {
# globalCallingHandlers(
# packageNotFoundError = function(err) {
# try(pak::handle_package_not_found(err))
# }
# )
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment