available
available copied to clipboard
`available_on_cran` should set `R_CRAN_SRC` environment variable when calling `tools:::CRAN_archive_db`
Discovered when running the following, with my system unable to connect to CRAN.R-project.org:
available::available("testpkg")
#> Error in url(sprintf("%s/%s", cran, path), open = "rb") :
#> cannot open the connection to 'https://CRAN.R-project.org/src/contrib/Meta/archive.rds'
#> In addition: Warning message:
#> In url(sprintf("%s/%s", cran, path), open = "rb") :
#> URL 'https://CRAN.R-project.org/src/contrib/Meta/archive.rds': status was 'Couldn't connect to server'
Issue:
Currently, available_on_cran()
calls tools:::CRAN_archive_db()
. By default, tools.R uses "https://CRAN.R-project.org" (obtained from .get_standard_repository_URLs()
) as the base URL to fetch, unless Sys.getenv("R_CRAN_SRC")
is set.
This differs from the expected behavior, which would be to use a mirror or the value from repos
.
A possible solution would be to set R_CRAN_SRC
when calling tools:::CRAN_archive_db()
to the repos
parameter. Confirmed by setting Sys.setenv(R_CRAN_SRC = "https://cloud.r-project.org")
and re-running available::available("testpkg")
.
I don't know if there is a good reason for tools::: CRAN_archive_db()
not using the default repo, possibly yes, because the default repo might be out of date, and for this you'd want the latest data possible.
In any case, if I understand correctly, you can already use the different mirror, by setting that env var, so I don't think any change is needed in available.
R_CRAN_SRC
is undocumented, at least as far as I could find (only hit on Google is https://svn.r-project.org/R/trunk/src/library/tools/R/CRANtools.R). My thought was that available should 'just work' and handle this by setting it when calling a private function within R tools, which would be easy enough.
There is no guarantee that setting the current repo will make it "just work". What if that is offline or slow, and the main CRAN site is online? And even if the current mirror is online, the main site has more recent data.
Btw. pak::pkg_name_check()
is an alternative of this package, and it works if CRAN is offline:
❯ pak::pkg_name_check("foo")
╔══════════════════════════════════════════════════════════════════════════════╗
║ –*– foo –*– ║
╚══════════════════════════════════════════════════════════════════════════════╝
┌──────────────────────────────────────────────────────────────────────────────┐
│ ✔ valid name ✔ CRAN ✔ Bioconductor ✔ not a profanity │
└──────────────────────────────────────────────────────────────────────────────┘
┌ Wikipedia ───────────────────────────────────────────────────────────────────┐
│ Foobar (from Foo) The terms foobar, foo, bar, baz, and others are used as │
│ metasyntactic variables and placeholder names in computer programming or │
│ computer-related documentation. They have been used to name entities such │
│ as variables, functions, and commands whose exact identity is unimportant │
│ and serve only to demonstrate a concept. │
└──────────────────────────────────────── https://en.wikipedia.org/wiki/Foobar ┘
┌ Wiktionary ──────────────────────────────────────────────────────────────────┐
│ foo Etymology 1: From Mandarin 府 (fǔ). │
│ foo (plural foos) │
│ (historical, obsolete) Alternative form of fu: an administrative │
│ subdivision of imperial China; the capital of such divisions. │
│ Etymology 2: From Chinese 福 (fú, “fortunate; prosperity, good luck”), via │
│ its use as 福星 (Fúxīng, “Jupiter”) in Chinese statues of the Three Lucky │
│ … │
└────────────────────────────────────────── https://en.wiktionary.org/wiki/foo ┘
┌ Acroynms (from Acromine) ────────────────────────────────────────────────────┐
│ No acronyms found. │
└──────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────┐
│ Sentiment: 😐 (0) │
└──────────────────────────────────────────────────────────────────────────────┘
There is no guarantee that setting the current repo will make it "just work". What if that is offline or slow, and the main CRAN site is online? And even if the current mirror is online, the main site has more recent data.
That's fair. I guess I expected that available_on_cran
would be consistent and use the repos
setting for the tools:::CRAN_archive_db
check as well. If available won't be changed, could the documentation be updated? I had to go digging into the R source code to find this environment variable.
R_CRAN_SRC
is now documented: https://github.com/wch/r-source/commit/a0e696a59458fedbfac08c681d663ad57479e4d4