Skip to content

cran_version() should be more robust #1857

Closed

Description

@ateucher

Several functions (use_release_checklist(), use_news_md()) call cran_version() to check if a package is on CRAN, which fails if a CRAN mirror is not set.

cran_version() calls available.packages() which in turn calls contrib.url() with repos = getOption("repos"). If the CRAN mirror is unset (the default value is "@CRAN@" in a factory fresh installation) it will prompt a user to choose in an interactive session, or fail otherwise:

withr::with_options(
  list(repos = c(CRAN = "@CRAN@")), 
  usethis:::cran_version()
)
#> Error in contrib.url(repos, type): trying to use CRAN without setting a mirror

This is showing up in revdep checks and CRAN checks for some usethis reverse depenencies which use use_news_md(). E.g., cynkra/fledge#683

cran_version() should not fail if there is no internet, or if there is no CRAN mirror set. In the former case, it should likely return NULL, which it currently returns if the package is not on CRAN. That seems like a reasonable fallback. If there is no CRAN mirror set we should try to set one locally, and also wrap that in a tryCatch(), returning NULL again if still unsuccessful.

This was surfaced in revdepchecks for #1849, was at first thought to be a false positive, and did not cause issues on incoming checks, but is causing failures for revdeps on CRAN.

Activity

  1. ateucher commented on Jun 8, 2023

    @ateucher
    CollaboratorAuthor

    If getOption(repos)["CRAN"] is NULL or NA (I don't know under what circumstances it would be set this way), cran_version() currently returns NULL. By locally setting a CRAN mirror we should be able to have success in more of these cases as well.

  2. krlmlr commented on Jun 12, 2023

    @krlmlr
    Member

    Are you aiming for a point release anytime soon? Thanks!

  3. jennybc commented on Jun 14, 2023

    @jennybc
    Member

    I don't have concrete plans because this is literally the only thing that would be in it. Since we just released 1 year's worth of maintenance, I suspect a few more smallish things will come up in the medium term. So maybe once there's a couple little things, we'll do a patch release.

  4. jennybc commented on Jun 23, 2023

    @jennybc
    Member

    I ended up needing to do a patch release anyway, so this fix will presumably be in usethis 2.2.1.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions