PredictiveEcology / Require

Simple R package to install and load packages conducive to a reproducible workflow
https://require.predictiveecology.org/
21 stars 6 forks source link

`install = "force", install_githubArgs = list(force = TRUE)` do not force installation #87

Closed CeresBarros closed 1 year ago

CeresBarros commented 1 year ago

I made the mistake of trying to update a loaded package to a specific commit. Require failed to install (as it should) but I can't seem to force the installation with Require

I tried to provide a reprex:

library(reproducible)
> Require::Require(c("CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212 (HEAD)"),  force = TRUE)
Using GITHUB_PAT to access files on GitHub
building package (R CMD build)
* checking for file 'reproducible/DESCRIPTION' ... OK
* preparing 'reproducible':
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building 'reproducible_2.0.2.9001.tar.gz'

  ... Built!
-- Installing from:
  -- GitHub: CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212
-- 1 of 1. Estimated time left: ...; est. finish: ...calculating
Warning: package ‘reproducible’ is in use and will not be installed

Restarting R session...

> Require::Require(c("CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212 (HEAD)"),
+                  purge = TRUE, install = "force", install_githubArgs = list(force = TRUE))
Using GITHUB_PAT to access files on GitHub
Skipping install of CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212, the SHA1 has not changed from last install

## but this works:
> devtools::install_github("CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212")
Using github PAT from envvar GITHUB_PAT
Downloading GitHub repo CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212
(...)
* DONE (reproducible)

my session info:

> sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8    LC_MONETARY=English_Canada.utf8
[4] LC_NUMERIC=C                    LC_TIME=English_Canada.utf8    

time zone: America/Vancouver
tzcode source: internal

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

other attached packages:
[1] reproducible_2.0.2.9001

loaded via a namespace (and not attached):
 [1] bit_4.0.5         miniUI_0.1.1.1    Require_0.3.0     compiler_4.3.0    crayon_1.5.2      promises_1.2.0.1 
 [7] Rcpp_1.0.10       stringr_1.5.0     blob_1.2.4        parallel_4.3.0    callr_3.7.3       later_1.3.1      
[13] fastmap_1.1.1     mime_0.12         R6_2.5.1          lobstr_1.1.2      htmlwidgets_1.6.2 profvis_0.3.8    
[19] shiny_1.7.4       DBI_1.1.3         rlang_1.1.1       stringi_1.7.12    cachem_1.0.8      httpuv_1.6.11    
[25] fs_1.6.2          pkgload_1.3.2     bit64_4.0.5       RSQLite_2.3.1     memoise_2.0.1     cli_3.6.1        
[31] magrittr_2.0.3    ps_1.7.5          digest_0.6.31     processx_3.8.1    rstudioapi_0.14   xtable_1.8-4     
[37] remotes_2.4.2     devtools_2.4.5    lifecycle_1.0.3   prettyunits_1.1.1 vctrs_0.6.2       glue_1.6.2       
[43] fpCompare_0.2.4   data.table_1.14.8 urlchecker_1.0.1  sessioninfo_1.2.2 pkgbuild_1.4.0    purrr_1.0.1      
[49] usethis_2.1.6     tools_4.3.0       ellipsis_0.3.2    htmltools_0.5.5  
eliotmcintire commented 1 year ago

This works for me. Can you confirm that it is still a problem with development branch?

In general, when this happens on Windows, it often means that another R session is open using the package.

CeresBarros commented 1 year ago

Thanks for looking into this @eliotmcintire -- I'll try to reproduce.

CeresBarros commented 1 year ago

Can't reproduce after closing all R sessions (previously I had them "restarted" but open because I was working on different interacting projects/packages). Does this mean that Require is a little more sensitive to multiple R sessions being open than devtools or remotes?

eliotmcintire commented 1 year ago

I don't think so. THose other ones have the same problem... it is R that has the problem. That warning (Warning: package ‘reproducible’ is in use and will not be installed) is not a Require error; it is an install.packages error. remotes uses install.packages under the hood, I believe.

eliotmcintire commented 1 year ago

Can't reproduce after closing all R sessions (previously I had them "restarted" but open because I was working on different interacting projects/packages).

In my experience, this is Rstudio on Windows that hangs onto packages for an unpredictable amount of time after an R restart within Rstudio.

CeresBarros commented 1 year ago

I don't think so. THose other ones have the same problem... it is R that has the problem. That warning (Warning: package ‘reproducible’ is in use and will not be installed) is not a Require error; it is an install.packages error. remotes uses install.packages under the hood, I believe.

Yes, but note that warning was not issued after restarting the session. At that point, Require skipped the install as if it had been installed already.

-- Installing from:
  -- GitHub: CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212
-- 1 of 1. Estimated time left: ...; est. finish: ...calculating
Warning: package ‘reproducible’ is in use and will not be installed

Restarting R session...

> Require::Require(c("CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212 (HEAD)"),
+                  purge = TRUE, install = "force", install_githubArgs = list(force = TRUE))
Using GITHUB_PAT to access files on GitHub
Skipping install of CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212, the SHA1 has not changed from last install

## but this works:
> devtools::install_github("CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212")
Using github PAT from envvar GITHUB_PAT
Downloading GitHub repo CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212
(...)
* DONE (reproducible)
eliotmcintire commented 1 year ago

Ah. That is a problem. I thinks it installed it, but it didn't... boom. That needs fixing. Though hard to "reprex" because it has to fail...

CeresBarros commented 1 year ago

I'll try to get a reprex

eliotmcintire commented 1 year ago

Ok. Made a PR #88

eliotmcintire commented 1 year ago

reprex:

try(remove.packages("reproducible"))
Require::clearRequirePackageCache("reproducible", ask = FALSE) # just in case some previous one had the bug
Require::Install("reproducible")                               # installs current CRAN version, which is older than SHA below
library(reproducible)                                          # load it
Require::Require(c("CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212 (HEAD)"))
packageVersion("reproducible") # will be 2.0.2 from CRAN

detach("package:reproducible", unload = TRUE)
# now installs correct SHA which is 2.0.2.9001
Require::Require(c("CeresBarros/reproducible@51ecfd2b1b9915da3bd012ce23f47d4b98a9f212 (HEAD)")) 
packageVersion("reproducible") # was incorrectly 2.0.2 from CRAN prior to PR #87
eliotmcintire commented 1 year ago

Pulled into development