Skip to content
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

renv::install() fails when CRAN-like repositories are in renv.lock #1578

Closed
ezraporter opened this issue Jul 21, 2023 · 2 comments · Fixed by #1589
Closed

renv::install() fails when CRAN-like repositories are in renv.lock #1578

ezraporter opened this issue Jul 21, 2023 · 2 comments · Fixed by #1589
Labels
bug an unexpected problem or unintended behavior install 🧺

Comments

@ezraporter
Copy link

My institution uses a drat repository in our GitHub Enterprise to distribute packages internally. Since renv 0.17.0 renv::install() seems to fail for any package (even CRAN packages) when our drat repo is in my renv.lock.

I did some digging and it seems like the regression may have occurred at 62c73d9 where a warning was upgraded to an error in available-packages.R.

reprex

I created a drat repo at https://ezraporter.github.io/drat to show the issue:

renv.lock:

...
    "Repositories": [
      {
        "Name": "CRAN",
        "URL": "https://cran.rstudio.com"
      },
      {
        "Name": "OTHERAN",
        "URL": "https://ezraporter.github.io/drat"
      }
    ]
  ...
# Fails
renv::install("dplyr")
Show error message
Error: package 'dplyr' is not available
Traceback (most recent calls last):
15: renv::install("dplyr")
14: retrieve(packages)
13: handler(package, renv_retrieve_impl(package))
12: renv_retrieve_impl(package)
11: withCallingHandlers(renv_available_packages_latest(package), 
        error = function(err) stopf("package '%s' is not available", 
            package))
10: renv_available_packages_latest(package)
 9: map(errors$data(), warning)
 8: lapply(x, f, ...)
 7: FUN(X[[i]], ...)
 6: withRestarts({
        .Internal(.signalCondition(cond, message, call))
        .Internal(.dfltWarn(message, call))
    }, muffleWarning = function() NULL)
 5: withOneRestart(expr, restarts[[1L]])
 4: doWithOneRestart(return(expr), restart)
 3: <condition-handler>(...)
 2: stopf("package '%s' is not available", package)
 1: stop(sprintf(fmt, ...), call. = call.)
# Works but issues some warning messages due to the drat repo not serving binaries
utils::install.packages("dplyr")

#> ...
#> Warning: unable to access index for repository https://ezraporter.github.io/drat/bin/macosx/big-sur-arm64/contrib/4.2:
#>  cannot open URL 'https://ezraporter.github.io/drat/bin/macosx/big-sur-arm64/contrib/4.2/PACKAGES'
#> ...

Ideally renv would also be able to install and track sources for packages downloaded from drat repos.

In renv 0.16.0, this works:

renv::install("dummypackage")

where dummypackage is a package in https://ezraporter.github.io/drat. renv::snapshot() generates the right thing in my renv.lock:

...
"Packages": {
    "dummypackage": {
      "Package": "dummypackage",
      "Version": "0.1.0",
      "Source": "Repository",
      "Repository": "OTHERAN", # <-- repo is tracked!
      "Hash": "76b8b050c24559ba3b842a564852c5a1",
      "Requirements": []
    },
...

In the latest development version:

# Fails
renv::install("dummypackage")

# Works
utils::install.packages("dummypackage")

However, renv::snapshot() doesn't generate the right thing:

...
"Packages": {
    "dummypackage": {
      "Package": "dummypackage",
      "Version": "0.1.0",
      "Source": "unknown",
      "Hash": "76b8b050c24559ba3b842a564852c5a1"
    }
...

Session Info

Session Info
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.1  tools_4.2.1     renv_1.0.0.9000
@kevinushey
Copy link
Collaborator

Thanks for the bug report. A more straightforward reprex:

options(repos = c(
  CRAN = "https://cran.rstudio.com",
  OTHER = "https://ezraporter.github.io/drat"
))

renv::install("dplyr")

@kevinushey kevinushey added bug an unexpected problem or unintended behavior install 🧺 labels Jul 22, 2023
@kevinushey kevinushey added this to the 1.0.1 milestone Jul 22, 2023
@kevinushey
Copy link
Collaborator

The problem here is that we're signaling a hard error when a repository fails to return available packages:

# propagate errors
errors <- as.list(errors)
enumerate(errors, function(url, errors) {
if (empty(errors))
return()
for (error in errors)
warning(error)
fmt <- "could not retrieve available packages for url %s"
stopf(fmt, shQuote(url))
})

Perhaps that shouldn't be an error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior install 🧺
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants