diff --git a/DESCRIPTION b/DESCRIPTION index d3f157d..851f2ec 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,8 +3,8 @@ Type: Package Title: Informative Messages About Outdated Packages Version: 0.1.0 Authors@R: person("Jacob", "Scott", email = "jscott2718@gmail.com", role = c("aut", "cre")) -Description: When a package is loaded, the source repository is checked for - new versions and a message is shown in the console indicating whether the +Description: When a package is loaded, the source repository is checked for + new versions and a message is shown in the console indicating whether the package is out of date. License: MIT + file LICENSE Encoding: UTF-8 diff --git a/R/available_version.R b/R/available_version.R index a857b2e..8f9c5aa 100644 --- a/R/available_version.R +++ b/R/available_version.R @@ -123,8 +123,8 @@ available_version_impl_repo <- function(pkg, repo = NULL, repo_alias = NULL) { sub(x = _, "/R/.+$", "") |> sub(x = _, "/src/contrib$", "") - repo_alias <- names(repos_option)[grepl(pattern, repos_option, fixed = TRUE)] - if (length(repo_alias) == 0L || identical(repo_alias, "")) + repo_alias <- names(repos_option)[grepl(pattern, repos_option, fixed = TRUE)][1] + if (is.null(repo_alias) || any(is.na(repo_alias)) || identical(repo_alias, "")) repo_alias <- repo } diff --git a/R/updateme_on.R b/R/updateme_on.R index 93c325b..23b7356 100644 --- a/R/updateme_on.R +++ b/R/updateme_on.R @@ -3,27 +3,20 @@ #' These functions may be useful if you find the slight delay caused by #' updateme looking up new package versions to be slowing down your workflow. #' -#' @return `NULL`, invisibly +#' @return The old `updateme.on` option, as returned by `options()` #' @export #' #' @seealso [updateme_sources_set()] to turn updateme off for individual #' packages #' -#' @examples -#' if (FALSE) { -#' updateme_off() -#' updateme_on() -#' } updateme_on <- function() { options(updateme.on = TRUE) - invisible(NULL) } #' @rdname updateme_on #' @export updateme_off <- function() { options(updateme.on = FALSE) - invisible(NULL) } updateme_is_on <- function() { diff --git a/R/updateme_sources_set.R b/R/updateme_sources_set.R index 6d5d5ed..8a84f47 100644 --- a/R/updateme_sources_set.R +++ b/R/updateme_sources_set.R @@ -52,37 +52,38 @@ #' packages #' #' @examples -#' if (FALSE) { -#' -#' # If you want to check non-standard repos for new versions of packages, -#' # you'll first have to set the repos global option. Note that each -#' # option must be named for compatibility with updateme -#' options(repos = c( -#' -#' # Your default repos, e.g. c(CRAN = "https://cloud.r-project.org") -#' getOption("repos"), -#' -#' # The tidyverse r-universe, including dev versions of tidyverse packages -#' tidyverse = "https://tidyverse.r-universe.dev", -#' -#' # The r-lib r-universe, including dev versions of infrastructure packages -#' # like {cli}, {rlang}, etc -#' rlib = "https://r-lib.r-universe.dev" -#' )) -#' -#' # 1. New versions will first be looked up in the tidyverse r-universe -#' # 2. If not found, they will be looked up from your usual CRAN mirror -#' # 3. {bslib} will always be first looked up from GitHub -#' # 4. {cli} will always be first looked up from the r-lib r-universe -#' updateme_sources_set( -#' "tidyverse", -#' "CRAN", -#' bslib = "https://github.com/rstudio/bslib", # Name is optional here -#' cli = "rlib" -#' ) +#' # If you want to check non-standard repos for new versions of packages, +#' # you'll first have to set the repos global option. Note that each +#' # option must be named for compatibility with updateme +#' old_repos <- options(repos = c( +#' +#' # Your default CRAN mirror will likely be something like this +#' CRAN = "https://cloud.r-project.org", +#' +#' # The r-lib r-universe, including dev versions of infrastructure packages +#' # like cli, rlang, etc +#' `r-lib` = "https://r-lib.r-universe.dev" +#' )) +#' +#' # 1. New versions will first be looked up from the r-lib R universe by default +#' # 2. If not found, they will be looked up from the usual CRAN mirror +#' # 3. dplyr will always be first looked up from GitHub +#' # 4. ggplot2 won't be looked up or notified about +#' old_updateme_sources <- updateme_sources_set( +#' "r-lib", +#' "CRAN", +#' dplyr = "https://github.com/tidyverse/dplyr", # Name is optional here +#' ggplot2 = NA +#' ) +#' +#' # memoise should now be looked up from the r-lib r-universe +#' if (interactive()) { +#' library(memoise) #' } #' -# TODO: Add .append arg? +#' # Restore old options +#' options(old_repos) +#' options(old_updateme_sources) updateme_sources_set <- function(...) { options(updateme.sources = updateme_sources_set_impl(...)) } @@ -119,17 +120,17 @@ updateme_sources_validate <- function(src, pkg = NULL, throw = cli::cli_abort) { handle_no_sources <- function() { if (!is.null(throw)) { - repos <- names(getOption("repos")) + repos <- cli::cli_vec(names(getOption("repos")), style = list("vec-last" = " or ")) throw(call = caller_call(6), c( "Invalid package source {.val {src}}.", - "i" = "Package sources must be either:", - " " = '1. One of {.code names(getOption("repos"))}', - " " = "2. {.val bioc} to check te version on Bioconductor", - " " = "3. {.val github}/{.val gitlab} to check the version on GitHub/GitLab if possible", - " " = "4. The URL of a specific GitHub repository, e.g. {.url https://github.com/wurli/updateme}", - " " = "5. The URL of a specific GitLab repository, e.g. {.url https://gitlab.com/r-packages/yum}", - " " = "6. {.val NA} to turn {.pkg updateme} off for a package", - " " = "7. {.val NULL} to return to the default behaviour" + "i" = "Inputs must be:", + " " = '- One of {.code names(getOption("repos"))}, i.e. {.val {repos}}', + " " = "- {.val bioc} to check the version on Bioconductor", + " " = "- {.val github}/{.val gitlab} to check the version on GitHub/GitLab if possible", + " " = "- The URL of a specific GitHub repository, e.g. {.val https://github.com/wurli/updateme}", + " " = "- The URL of a specific GitLab repository, e.g. {.val https://gitlab.com/r-packages/yum}", + " " = "- {.val NA} to turn {.pkg updateme} off for a package", + " " = "- {.val NULL} to return to the default behaviour" )) } NULL diff --git a/R/zzz.R b/R/zzz.R index aec8c67..8fa238f 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -5,6 +5,9 @@ max_age = 60 * getOption("updateme.cache_expiry", 60) ) + # Note: <<- does not modify the global environment, it simply memoises + # existing functions included in this package. This is the approach + # recommended by the {memoise} package itself - see ?memoise::memoise available_packages <<- memoise::memoise( available_packages, cache = updateme_cache ) diff --git a/man/updateme_on.Rd b/man/updateme_on.Rd index b6428ae..a7816e6 100644 --- a/man/updateme_on.Rd +++ b/man/updateme_on.Rd @@ -10,18 +10,12 @@ updateme_on() updateme_off() } \value{ -\code{NULL}, invisibly +The old \code{updateme.on} option, as returned by \code{options()} } \description{ These functions may be useful if you find the slight delay caused by updateme looking up new package versions to be slowing down your workflow. } -\examples{ -if (FALSE) { - updateme_off() - updateme_on() -} -} \seealso{ \code{\link[=updateme_sources_set]{updateme_sources_set()}} to turn updateme off for individual packages diff --git a/man/updateme_sources_set.Rd b/man/updateme_sources_set.Rd index e4464aa..408f63a 100644 --- a/man/updateme_sources_set.Rd +++ b/man/updateme_sources_set.Rd @@ -59,36 +59,38 @@ to configure a personal access token (PAT): } \examples{ -if (FALSE) { +# If you want to check non-standard repos for new versions of packages, +# you'll first have to set the repos global option. Note that each +# option must be named for compatibility with updateme +old_repos <- options(repos = c( - # If you want to check non-standard repos for new versions of packages, - # you'll first have to set the repos global option. Note that each - # option must be named for compatibility with updateme - options(repos = c( + # Your default CRAN mirror will likely be something like this + CRAN = "https://cloud.r-project.org", - # Your default repos, e.g. c(CRAN = "https://cloud.r-project.org") - getOption("repos"), + # The r-lib r-universe, including dev versions of infrastructure packages + # like cli, rlang, etc + `r-lib` = "https://r-lib.r-universe.dev" +)) - # The tidyverse r-universe, including dev versions of tidyverse packages - tidyverse = "https://tidyverse.r-universe.dev", +# 1. New versions will first be looked up from the r-lib R universe by default +# 2. If not found, they will be looked up from the usual CRAN mirror +# 3. dplyr will always be first looked up from GitHub +# 4. ggplot2 won't be looked up or notified about +old_updateme_sources <- updateme_sources_set( + "r-lib", + "CRAN", + dplyr = "https://github.com/tidyverse/dplyr", # Name is optional here + ggplot2 = NA +) - # The r-lib r-universe, including dev versions of infrastructure packages - # like {cli}, {rlang}, etc - rlib = "https://r-lib.r-universe.dev" - )) - - # 1. New versions will first be looked up in the tidyverse r-universe - # 2. If not found, they will be looked up from your usual CRAN mirror - # 3. {bslib} will always be first looked up from GitHub - # 4. {cli} will always be first looked up from the r-lib r-universe - updateme_sources_set( - "tidyverse", - "CRAN", - bslib = "https://github.com/rstudio/bslib", # Name is optional here - cli = "rlib" - ) +# memoise should now be looked up from the r-lib r-universe +if (interactive()) { + library(memoise) } +# Restore old options +options(old_repos) +options(old_updateme_sources) } \seealso{ \code{\link[=updateme_on]{updateme_on()}} and \code{\link[=updateme_off]{updateme_off()}} to disable updateme for all