r-lib / remotes

Install R packages from GitHub, GitLab, Bitbucket, git, svn repositories, URLs
https://remotes.r-lib.org/
Other
330 stars 152 forks source link

Improve install_* errors when one of the repos is not found #724

Closed lgaborini closed 1 year ago

lgaborini commented 1 year ago

I have lost hours to debug this!
In my setup I have a local package repository, such as the ones created by {drat}, that is added on startup to the options()$repos entry.
According to the docs, local repositories must start with file:.

If the local repository actually exists, {remotes} installs packages without issues, from CRAN, git or any other valid source.

If the local repository is not available (e.g. the script is running inside a Docker container, but the repository is an unmounted volume), the error message is extremely unhelpful, and leads you thinking that the issue affects the package you are trying to install, or its installation method (e.g. a privately hosted Git repo requiring authentication).

# default CRAN
repos_default <- c("CRAN" = "@CRAN@")

# add a local CRAN-like repository
repos_drat <- repos_default
repos_drat["drat"] <- "file://drat"

withr::with_options(
   list(repos = repos_drat), {
      remotes::install_git("https://github.com/rstudio/bookdown.git", force = TRUE)
   }
)
#> Downloading git repo https://github.com/rstudio/bookdown.git
#> Error: Failed to install 'bookdown' from Git:
#>   cannot open the connection

Created on 2022-09-08 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.0 (2022-04-22 ucrt) #> os Windows 10 x64 (build 19044) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_Switzerland.utf8 #> ctype English_Switzerland.utf8 #> tz Europe/Berlin #> date 2022-09-08 #> pandoc 2.18 @ C:/Users/LorenzoGaborini/apps_offline/RStudioPreview/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.3.0 2022-04-25 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0) #> evaluate 0.16 2022-08-09 [1] CRAN (R 4.2.1) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.0) #> git2r 0.30.1 2022-03-16 [1] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> htmltools 0.5.3 2022-07-18 [1] CRAN (R 4.2.1) #> knitr 1.40 2022-08-24 [1] CRAN (R 4.2.1) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.2.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.1) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.0) #> R.utils 2.12.0 2022-06-28 [1] CRAN (R 4.2.1) #> remotes 2.4.2 2021-11-30 [1] CRAN (R 4.2.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.1) #> rlang 1.0.4 2022-07-12 [1] CRAN (R 4.2.1) #> rmarkdown 2.16 2022-08-24 [1] CRAN (R 4.2.1) #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> stringi 1.7.8 2022-07-11 [1] CRAN (R 4.2.1) #> stringr 1.4.1.9000 2022-09-08 [1] git2r (https://github.com/hadley/stringr.git@792bc92) #> styler 1.7.0 2022-03-13 [1] CRAN (R 4.2.0) #> tibble 3.1.8 2022-07-22 [1] CRAN (R 4.2.1) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.32 2022-08-10 [1] CRAN (R 4.2.1) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0) #> #> [1] C:/Users/LorenzoGaborini/R/R-4.2.0/library #> #> ────────────────────────────────────────────────────────────────────────────── ```

There are no issues if the drat repository is not added to the list, or it points to a non-file: URI. It does not even need to exist: in this case the warning is explicit but not blocking (disregard the {rlang} error, the package should install fine).

# default CRAN
repos_default <- c("CRAN" = "@CRAN@")

# add a local CRAN-like repository
repos_drat <- repos_default
repos_drat["drat"] <- "drat"   # not existing

withr::with_options(
   list(repos = repos_drat), {
      remotes::install_git("https://github.com/rstudio/bookdown.git", force = TRUE)
   }
)
#> Downloading git repo https://github.com/rstudio/bookdown.git
#> rlang (1.0.4 -> 1.0.5) [CRAN]
#> Installing 1 packages: rlang
#> Warning: unable to access index for repository drat/src/contrib:
#>   cannot open URL 'drat/src/contrib/PACKAGES'
#> Warning: unable to access index for repository drat/bin/windows/contrib/4.2:
#>   cannot open URL 'drat/bin/windows/contrib/4.2/PACKAGES'
#> package 'rlang' successfully unpacked and MD5 sums checked
#> Warning: cannot remove prior installation of package 'rlang'
#> Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
#> C:\Users\USER\R\R-4.2.0\library\00LOCK\rlang\libs\x64\rlang.dll to
#> C:\Users\USER\R\R-4.2.0\library\rlang\libs\x64\rlang.dll: Permission
#> denied
#> Warning: restored 'rlang'
#> 
#> The downloaded binary packages are in
#>  C:\Users\USER\AppData\Local\Temp\RtmpcdGJR0\downloaded_packages
#>          checking for file 'C:\Users\USER\AppData\Local\Temp\RtmpcdGJR0\file2e8946ebd2d67/DESCRIPTION' ...     checking for file 'C:\Users\USER\AppData\Local\Temp\RtmpcdGJR0\file2e8946ebd2d67/DESCRIPTION' ...   ✔  checking for file 'C:\Users\USER\AppData\Local\Temp\RtmpcdGJR0\file2e8946ebd2d67/DESCRIPTION' (1.3s)
#>       ─  preparing 'bookdown': (2.1s)
#>    checking DESCRIPTION meta-information ...     checking DESCRIPTION meta-information ...   ✔  checking DESCRIPTION meta-information
#>       ─  checking for LF line-endings in source and make files and shell scripts (855ms)
#>       ─  checking for empty or unneeded directories
#>       ─  building 'bookdown_0.28.2.tar.gz'
#>      
#> 

Created on 2022-09-08 with reprex v2.0.2

Thanks!

gaborcsardi commented 1 year ago

What's the output of traceback() right after the error?

lgaborini commented 1 year ago
Downloading git repo https://github.com/rstudio/bookdown.git
Error: Failed to install 'bookdown' from Git:
  cannot open the connection
> traceback()
9: stop(remote_install_error(remotes[[i]], e))
8: value[[3L]](cond)
7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
6: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch(res[[i]] <- install_remote(remotes[[i]], ...), error = function(e) {
       stop(remote_install_error(remotes[[i]], e))
   })
4: install_remotes(remotes, credentials = credentials, dependencies = dependencies, 
       upgrade = upgrade, force = force, quiet = quiet, build = build, 
       build_opts = build_opts, build_manual = build_manual, build_vignettes = build_vignettes, 
       repos = repos, type = type, ...)
3: remotes::install_git("https://github.com/rstudio/bookdown.git", 
       force = TRUE) at #3
2: force(code)
1: withr::with_options(list(repos = repos_drat), {
       remotes::install_git("https://github.com/rstudio/bookdown.git", 
           force = TRUE)
   })

And here is a Docker for the reprex.

gaborcsardi commented 1 year ago

This is coming from available.packages() / install.packages(), so we cannot fix it in remotes:

❯ options(repos = c(drat = "file:///drat"))
❯ av <- install.packages("cli")
Installing package into ‘/Users/gaborcsardi/Library/R/arm64/4.2/library’
(as ‘lib’ is unspecified)
Error in read.dcf(file = tmpf) : cannot open the connection
In addition: Warning message:
In read.dcf(file = tmpf) :
  cannot open compressed file '/drat/src/contrib/PACKAGES', probable reason 'No such file or directory'