From eb766256b0e91102a0511351227a9f12c4af4706 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 30 Jul 2023 05:20:12 -0700 Subject: [PATCH 1/2] Fix #150 fix #149 fix#152 (#151) * Fix #150 fix #149 * Retry when hit by r-hub/pkgsearch#117 To make resolve more determinstic --- DESCRIPTION | 2 +- R/memo_misc.R | 20 +++++++++++++++++++- R/resolve.R | 8 ++++---- tests/testthat/test_resolve.R | 2 ++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c30c58d..553b14c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rang Title: Reconstructing Reproducible R Computational Environments -Version: 0.2.0 +Version: 0.2.1 Authors@R: c(person("Chung-hong", "Chan", , "chainsawtiney@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6232-7530")), diff --git a/R/memo_misc.R b/R/memo_misc.R index c8b3262..9a2da1f 100644 --- a/R/memo_misc.R +++ b/R/memo_misc.R @@ -5,7 +5,25 @@ NULL ## one hr -.memo_search <- memoise::memoise(pkgsearch::cran_package_history, cache = cachem::cache_mem(max_age = 60 * 60)) +.cran_package_history <- function(package, max_retries = 5) { + n_retries <- 0 + while(n_retries < max_retries) { + tryCatch({ + return(pkgsearch::cran_package_history(package)) + }, error = function(e) { + if (grepl("parse error: premature EOF", e$message)) { + n_retries <<- n_retries + 1 + ##message("retrying in 2s...") + Sys.sleep(2) + } else { + stop(e) + } + }) + } + stop("Can't query this package: ", package, call. = FALSE) +} + +.memo_search <- memoise::memoise(.cran_package_history, cache = cachem::cache_mem(max_age = 60 * 60)) .rver <- function() { suppressWarnings(jsonlite::fromJSON(readLines("https://api.r-hub.io/rversions/r-versions"), simplifyVector = TRUE)) diff --git a/R/resolve.R b/R/resolve.R index 3bc7937..a5af2cc 100644 --- a/R/resolve.R +++ b/R/resolve.R @@ -456,17 +456,17 @@ print.rang <- function(x, all_pkgs = FALSE, ...) { return(res) } -.gh <- function(path,ref = NULL,...){ +.gh <- function(path,ref = NULL,...) { url <- httr::parse_url("https://api.github.com/") url <- httr::modify_url(url, path = path) token <- Sys.getenv("GITHUB_PAT", NA_character_) - if(is.na(token)){ + if(is.na(token)) { token <- Sys.getenv("GITHUB_TOKEN", NA_character_) } - if(is.na(token)){ + if(is.na(token)) { token <- "" } - config <- httr::add_headers(Accept = "application/vnd.github.v3+json",Authorization=token) + config <- httr::add_headers(Accept = "application/vnd.github.v3+json", Authorization = paste0("token ", token)) params <- list(ref = ref,...) request_results <- httr::GET(httr::modify_url(url, path = path), config, query = params) status_code <- httr::status_code(request_results) diff --git a/tests/testthat/test_resolve.R b/tests/testthat/test_resolve.R index 99bfc3b..44f23a6 100644 --- a/tests/testthat/test_resolve.R +++ b/tests/testthat/test_resolve.R @@ -146,6 +146,8 @@ test_that("Non-cran must enforce caching ref #22", { ## }) test_that("Integration of as_pkgrefs() in resolve() for sessionInfo()", { + skip_if_offline() + skip_on_cran() x <- resolve(c("cran::sna"), snapshot_date = "2020-05-01", query_sysreqs = FALSE) si <- readRDS("../testdata/sessionInfo2.RDS") expect_error(graph <- resolve(si, snapshot_date = "2020-05-01", query_sysreqs = FALSE), NA) From 169f1be9e4bd71899754a073454dee046336920c Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 30 Jul 2023 14:50:58 +0200 Subject: [PATCH 2/2] Update README doc [no ci] --- README.Rmd | 6 +----- README.md | 4 ++-- inst/CITATION | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.Rmd b/README.Rmd index bfd2fd1..e553b93 100644 --- a/README.Rmd +++ b/README.Rmd @@ -27,11 +27,7 @@ To reconstruct a historical R computational environment, this package assumes on Please cite this package as: -Chan CH, Schoch D (2023) rang: Reconstructing reproducible R computational environments. arXiv preprint:[2303.04758](https://doi.org/10.48550/arXiv.2303.04758) - -Please cite this package as: - -Chan CH, Schoch D (2023) rang: Reconstructing reproducible R computational environments. arXiv preprint:[2303.04758](https://doi.org/10.48550/arXiv.2303.04758) +Chan CH, Schoch D (2023) rang: Reconstructing reproducible R computational environments. PLOS ONE [https://doi.org/10.1371/journal.pone.0286761](https://doi.org/10.1371/journal.pone.0286761) ## Installation diff --git a/README.md b/README.md index d54b04a..ac13611 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ of R. Please cite this package as: Chan CH, Schoch D (2023) rang: Reconstructing reproducible R -computational environments. arXiv -preprint:[2303.04758](https://doi.org/10.48550/arXiv.2303.04758) +computational environments. PLOS ONE + ## Installation diff --git a/inst/CITATION b/inst/CITATION index 963101a..5dfee90 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -3,8 +3,8 @@ citHeader("To cite rang in publications use:") bibentry(bibtype = "article", title = "rang: Reconstructing reproducible R computational environments", - journal = "arXiv preprint 2303.04758", + journal = "PLOS ONE", author = c(person("Chung-hong", "Chan"), person("David", "Schoch")), url = "https://github.com/chainsawriot/rang", year = 2023, - doi = "10.48550/arXiv.2303.04758") + doi = "10.1371/journal.pone.0286761")