r-lib / pak

A fresh approach to package installation
https://pak.r-lib.org
679 stars 63 forks source link

Feature request: Detect and let the user know when a package is no longer on CRAN (or any repo in the list) with a clearer error #441

Open billdenney opened 1 year ago

billdenney commented 1 year ago

When I just tried to install a long list of packages with pkg_install(), I got an error:

Error: ! error in pak subprocess
Caused by error: 
! invalid version specification 'NA'

Reprex below:

install.packages("pak")
#> Installing package into 'C:/Users/wdenn/AppData/Local/R/win-library/4.2'
#> (as 'lib' is unspecified)
#> package 'pak' successfully unpacked and MD5 sums checked
#> Warning: cannot remove prior installation of package 'pak'
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\cli\libs\x64\cli.dll to C:
#> \Users\wdenn\AppData\Local\R\win-library\4.2\pak\library\cli\libs\x64\cli.dll:
#> Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\curl\libs\x64\curl.dll to C:
#> \Users\wdenn\AppData\Local\R\win-library\4.2\pak\library\curl\libs\x64\curl.dll:
#> Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\filelock\libs\x64\filelock.dll
#> to C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\pak\library\filelock\libs\x64\filelock.dll: Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\glue\libs\x64\glue.dll to C:
#> \Users\wdenn\AppData\Local\R\win-library\4.2\pak\library\glue\libs\x64\glue.dll:
#> Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\jsonlite\libs\x64\jsonlite.dll
#> to C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\pak\library\jsonlite\libs\x64\jsonlite.dll: Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\lpSolve\libs\x64\lpSolve.dll
#> to C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\pak\library\lpSolve\libs\x64\lpSolve.dll: Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\pkgcache\libs\x64\pkgcache.dll
#> to C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\pak\library\pkgcache\libs\x64\pkgcache.dll: Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\processx\libs\x64\processx.dll
#> to C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\pak\library\processx\libs\x64\processx.dll: Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\ps\libs\x64\ps.dll to C:
#> \Users\wdenn\AppData\Local\R\win-library\4.2\pak\library\ps\libs\x64\ps.dll:
#> Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\rappdirs\libs\x64\rappdirs.dll
#> to C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\pak\library\rappdirs\libs\x64\rappdirs.dll: Permission denied
#> Warning in file.copy(savedcopy, lib, recursive = TRUE):
#> problem copying C:\Users\wdenn\AppData\Local\R\win-
#> library\4.2\00LOCK\pak\library\zip\libs\x64\zip.dll to C:
#> \Users\wdenn\AppData\Local\R\win-library\4.2\pak\library\zip\libs\x64\zip.dll:
#> Permission denied
#> Warning: restored 'pak'
#> 
#> The downloaded binary packages are in
#>  C:\Users\wdenn\AppData\Local\Temp\RtmpGoSeR2\downloaded_packages
pak::repo_add("MRAN@2022-12-05")
pak::pkg_install(c(
  "arsenal",
  "assertr",
  "bayesplot",
  "binom",
  "bit64",
  "bookdown",
  "brms",
  "broom",
  "broom.mixed",
  "caTools",
  "censReg",
  "ciTools",
  "clustermq",
  "countrycode",
  "covr",
  "cowplot",
  "crch",
  "daff",
  "devtools",
  "DiagrammeR",
  "DiagrammeRsvg",
  "directlabels",
  "digest",
  "docxtractr",
  "DoseFinding",
  "dplyr",
  "drake",
  "emmeans",
  "errors",
  "extrafont",
  "forcats",
  "formulops",
  "future",
  "GGally",
  "ggdendro",
  "ggplot2",
  "ggraph",
  "ggsignif",
  "glmmTMB",
  "gsDesign",
  "gt",
  "gtools",
  "hexbin",
  "Hmisc",
  "igraph",
  "installr",
  "janitor",
  "kableExtra",
  "knitcitations",
  "knitr",
  "lintr",
  "lme4",
  #"LogrankPower",
  "longpower",
  "loo",
  "lubridate",
  "microbenchmark",
  "mrgsolve",
  "mvtnorm",
  "naturalsort",
  "nlmixr",
  "nlmixr2",
  "NMdata",
  "pander",
  "parsnip",
  "pdftools", # sudo apt-get install libpoppler-cpp-dev
  "PKNCA",
  #"PKPDmisc",
  "physiology",
  "pmxTools",
  "PowerTOST",
  "printr",
  "purrr",
  "pwr",
  "Rcpp",
  "readr",
  "rentrez",
  "reprex",
  "reshape",
  "reticulate",
  "rio",
  "riverplot",
  # "rJava",
  "rlang",
  "rmarkdown",
  "rmutil",
  "roxygen2",
  "rstan",
  "rstanarm",
  "rstantools",
  "rsvg", # sudo apt-get install -y librsvg2-dev
  "shiny",
  "shinydashboard",
  "simstudy",
  "spelling",
  "ssh", # sudo apt-get install -y libssh-dev
  "stringi",
  "stringr",
  "styler",
  "survminer",
  "svglite",
  "swCRTdesign",
  "table1",
  #"tabulizer",
  "tarchetypes",
  "targets",
  "testthat",
  "tibble",
  "tidygraph",
  "tidyr",
  "tidyverse",
  "tinytest",
  "tidyxl",
  "truncdist",
  "truncnorm",
  "units",
  "unpivotr",
  "vpc",
  "vroom",
  "XML",
  "xpose",
  # For nlmixr development version:
  "symengine",
  "inline",
  "PreciseSums",
  "RcppArmadillo"
))
#> ℹ Loading metadata database
#> ℹ Loading metadata database✔ Loading metadata database ... done✔ Loading metadata database ... done
#> Error: ! error in pak subprocess
#> Caused by error: 
#> ! invalid version specification 'NA'

Created on 2022-12-05 with reprex v2.0.2

billdenney commented 1 year ago

I traced it back to a much simpler reprex, the daff package is no longer on CRAN, so this reprex gives the same error.

pak::pkg_install("daff")

I think that changes the request to be:

In this case, I had to determine the package that wasn't working by bifurcation. A note for what package is giving the subprocess error would be very helpful.

gaborcsardi commented 1 year ago

I see this for daff:

❯ pak::pkg_install("daff")
✔ Updated metadata database: 5.02 MB in 6 files.
✔ Updating metadata database ... done

→ Will install 1 package.
→ Will download 1 CRAN package (1.74 MB).
+ daff   0.3.5  ⬇ (1.74 MB)
ℹ Getting 1 pkg (1.74 MB)
✖ Failed to download daff 0.3.5 (aarch64-apple-darwin20)
✖ Failed to download 1 package.
Error:
! error in pak subprocess
Caused by error:
! Failed to download daff from `https://cloud.r-project.org/bin/macosx/big-sur-arm64/contrib/4.2/daff_0.3.5.tgz` and `https://mac.r-project.org/bin/macosx/big-sur-arm64/contrib/4.2/daff_0.3.5.tgz`.
Type .Last.error to see the more details.

I guess it was just archived, and the CRAN metadata is inconsistent.

For an archived/non-existent package I get this:

❯ pak::pkg_install("qwertyqwerty")
Error:
! error in pak subprocess
Caused by error:
! Could not solve package dependencies:
* qwertyqwerty: Can't find package called qwertyqwerty.
Type .Last.error to see the more details.

How would you improve this?

billdenney commented 1 year ago

Hi @gaborcsardi, apologies, I thought that my reprex was self-contained but it was not. I had set the MRAN repo as well, and that makes the error different. I agree that the errors you're seeing above are good. Here is the reprex I'm getting now with the current CRAN version of pak (version 0.3.1):

pak::repo_add("MRAN@2022-12-05")
pak::pkg_install("daff")
#> ℹ Loading metadata databaseℹ Loading metadata database✔ Loading metadata database ... done✔ Loading metadata database ... done
#> Error: ! error in pak subprocess
#> Caused by error: 
#> ! invalid version specification 'NA'

Created on 2022-12-06 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.1 (2022-06-23 ucrt) #> os Windows 10 x64 (build 22621) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz America/New_York #> date 2022-12-06 #> pandoc 2.19.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.4.1 2022-09-23 [1] CRAN (R 4.2.1) #> digest 0.6.30 2022-10-18 [1] CRAN (R 4.2.2) #> evaluate 0.18 2022-11-07 [1] CRAN (R 4.2.2) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.1) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.1) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.1) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.1) #> htmltools 0.5.3 2022-07-18 [1] CRAN (R 4.2.1) #> knitr 1.41 2022-11-18 [1] CRAN (R 4.2.2) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.1) #> pak 0.3.1 2022-09-08 [1] CRAN (R 4.2.2) #> purrr 0.3.5 2022-10-06 [1] CRAN (R 4.2.1) #> 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) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.1) #> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.2.1) #> rmarkdown 2.18 2022-11-09 [1] CRAN (R 4.2.2) #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.1) #> stringi 1.7.8 2022-07-11 [1] CRAN (R 4.2.1) #> stringr 1.5.0 2022-12-02 [1] CRAN (R 4.2.2) #> styler 1.8.1 2022-11-07 [1] CRAN (R 4.2.2) #> vctrs 0.5.0 2022-10-22 [1] CRAN (R 4.2.2) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.1) #> xfun 0.34 2022-10-18 [1] CRAN (R 4.2.2) #> yaml 2.3.6 2022-10-18 [1] CRAN (R 4.2.1) #> #> [1] C:/Users/wdenn/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-4.2.1/library #> #> ────────────────────────────────────────────────────────────────────────────── ```

I see that you're using a mac while I'm on Windows. Could that make a difference?

gaborcsardi commented 1 year ago

That should not make a difference:

❯ pak::repo_add("MRAN@2022-12-05")
❯ pak::pkg_install("daff")
✔ Loading metadata database ... done

→ Will install 1 package.
→ Will download 1 CRAN package (1.74 MB).
+ daff   0.3.5  ⬇ (1.74 MB)
ℹ Getting 1 pkg (1.74 MB)
✖ Failed to download daff 0.3.5 (aarch64-apple-darwin20)
✖ Failed to download 1 package.
Error:
! error in pak subprocess
Caused by error:
! Failed to download daff from `https://cran.microsoft.com/snapshot/2022-12-05/bin/macosx/big-sur-arm64/contrib/4.2/daff_0.3.5.tgz` and `https://mac.r-project.org/bin/macosx/big-sur-arm64/contrib/4.2/daff_0.3.5.tgz`.
Type .Last.error to see the more details.

❯ Sys.setenv(PKG_PLATFORMS = "source")
❯ pak::repo_add("MRAN@2022-12-05")
❯ pak::pkg_install("daff")
✔ Updating metadata database ... done
Error:
! error in pak subprocess
Caused by error:
! Could not solve package dependencies:
* daff: Can't find package called daff.
Type .Last.error to see the more details.
gaborcsardi commented 1 year ago

Can you try the nightly devel version? See the README.

billdenney commented 1 year ago

I got the same error with the nightly devel build (installed with install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/devel/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))).

gaborcsardi commented 1 year ago

Can you show the output of the installation, please? I.e. the output of

install.packages(
  "pak", 
  repos = sprintf(
    "https://r-lib.github.io/p/pak/devel/%s/%s/%s", 
    .Platform$pkgType, R.Version()$os, R.Version()$arch
  )
)
billdenney commented 1 year ago

> install.packages(
+     "pak", 
+     repos = sprintf(
+         "https://r-lib.github.io/p/pak/devel/%s/%s/%s", 
+         .Platform$pkgType, R.Version()$os, R.Version()$arch
+     )
+ )
Installing package into ‘C:/Users/wdenn/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://r-lib.github.io/p/pak/devel/win.binary/mingw32/x86_64/bin/windows/contrib/4.2/../../../../../../../mingw32/x86_64/pak_0.3.1.9000_R-4-2_x86_64-mingw32.zip'
Content type 'application/zip' length 8111747 bytes (7.7 MB)
downloaded 7.7 MB

The downloaded binary packages are in
    C:\Users\wdenn\AppData\Local\Temp\Rtmp8UNEqn\downloaded_packages
> 
gaborcsardi commented 1 year ago

I still get this:

❯ pak::repo_add("MRAN@2022-12-05")
❯ pak::pkg_install("daff")
✔ Updated metadata database: 3.71 MB in 4 files.
✔ Updating metadata database ... done
Error:
! error in pak subprocess
Caused by error:
! Could not solve package dependencies:
* daff: Can't find package called daff.
Type .Last.error to see the more details.

which is not bad. Do you still have this issue?