Skip to content

cran_version() should be more robust #1857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ateucher opened this issue Jun 8, 2023 · 4 comments · Fixed by #1858
Closed

cran_version() should be more robust #1857

ateucher opened this issue Jun 8, 2023 · 4 comments · Fixed by #1858

Comments

@ateucher
Copy link
Collaborator

ateucher commented Jun 8, 2023

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.

@ateucher
Copy link
Collaborator Author

ateucher commented Jun 8, 2023

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.

@krlmlr
Copy link
Member

krlmlr commented Jun 12, 2023

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

@jennybc
Copy link
Member

jennybc commented Jun 14, 2023

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.

@jennybc
Copy link
Member

jennybc commented Jun 23, 2023

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants