Skip to content

Commit

Permalink
fix: update examples to pass CRAN checks
Browse files Browse the repository at this point in the history
Also fix failures when a repo is duplicated in getOption("repos").
Also remove extra spaces in DESCRIPTION
  • Loading branch information
wurli committed Mar 13, 2024
1 parent 9fd7f44 commit d72086a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 81 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Type: Package
Title: Informative Messages About Outdated Packages
Version: 0.1.0
Authors@R: person("Jacob", "Scott", email = "[email protected]", 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
Expand Down
4 changes: 2 additions & 2 deletions R/available_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 1 addition & 8 deletions R/updateme_on.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
77 changes: 39 additions & 38 deletions R/updateme_sources_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...))
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
8 changes: 1 addition & 7 deletions man/updateme_on.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 26 additions & 24 deletions man/updateme_sources_set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d72086a

Please sign in to comment.