Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ URL:
https://Require.predictiveecology.org,
https://github.com/PredictiveEcology/Require
Date: 2026-09-04
Version: 2.1.1.9055
Version: 2.1.1.9057
Authors@R: c(
person(given = "Eliot J B",
family = "McIntire",
Expand All @@ -43,24 +43,14 @@ Imports:
tools,
utils
Suggests:
cli,
covr,
curl,
diffobj,
fpCompare,
gitcreds,
httr,
parallel,
pkgcache,
pkgload,
rematch2,
rmarkdown,
knitr,
rlang,
roxygen2,
rprojroot,
testthat (>= 3.0.0),
waldo,
withr
Encoding: UTF-8
Language: en-CA
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Dependency changes

* Require now needs R >= 4.3 (was 4.1), the oldest R version its checks run on (#220).
* Nine packages that nothing in Require's code or tests needs are no longer in Suggests (cli, covr, diffobj, fpCompare, pkgcache, rematch2, rlang, roxygen2, waldo), and `rprojroot` is gone too: `setupOff()` now looks for the `*.Rproj` folder with base R.
* Require's own downloads from GitHub that use the user's git credentials now go through `curl` instead of `httr`. `GETWauthThenNonAuth()` is unchanged and still returns an `httr` response, because the SpaDES packages read it with `httr`; `httr` stays in Suggests for it.

## Removed

Expand Down
48 changes: 33 additions & 15 deletions R/Require-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ masterMainHEAD <- function(url, need) {
token <- checkForToken()
# token <- NULL
# usesGitCreds <- requireNamespace("gitcreds", quietly = TRUE) &&
# requireNamespace("httr", quietly = TRUE)
# requireNamespace("curl", quietly = TRUE)
# if (usesGitCreds) {
# token <- getGitCredsToken()
# }
Expand Down Expand Up @@ -1341,9 +1341,9 @@ masterMainHEAD <- function(url, need) {
messageVerbose(e$message, verbose = verbose)
})
} else {
a <- try(GETWauthThenNonAuth(URL, token, verbose = verbose), silent = TRUE)
a <- try(curlGETauth(URL, token, verbose = verbose), silent = TRUE)
if (is(a, "try-error")) {
# as without a token: keep the error and try again; httr::content() of a
# as without a token: keep the error and try again; reading the content of a
# try-error stopped with "is.response(x) is not TRUE"
lastErr <- conditionMessage(attr(a, "condition"))
if (tryNum > 1)
Expand All @@ -1352,11 +1352,7 @@ masterMainHEAD <- function(url, need) {
warning(a)
next
}
# a <- httr::GET(url, httr::add_headers(Authorization = token))
# if (grepl("Bad credentials", a) || grepl("404", a$status_code))
# a <- httr::GET(url, httr::add_headers())
data <- httr::content(a, "raw")
writeBin(data, df)
writeBin(a$content, df)
}
if (file.exists(df))
break
Expand All @@ -1378,12 +1374,10 @@ masterMainHEAD <- function(url, need) {
outMasterMain <- try(download.file(urls[["TRUE"]][wh], destfile = destfile, quiet = TRUE), silent = TRUE)
} else {
outMasterMain <- try(silent = TRUE, {
a <- GETWauthThenNonAuth(urls[["TRUE"]][wh], token, verbose = verbose)
# a <- httr::GET(urls[["TRUE"]][wh], httr::add_headers(Authorization = token))
if (grepl("404", httr::http_status(a)$message))
a <- curlGETauth(urls[["TRUE"]][wh], token, verbose = verbose)
if (a$status_code == 404L)
stop()
data <- httr::content(a, "raw")
writeBin(data, destfile)
writeBin(a$content, destfile)
})
if (is.null(outMasterMain)) outMasterMain <- 0
}
Expand Down Expand Up @@ -1560,6 +1554,30 @@ GETWauthThenNonAuth <- function(url, token, verbose = getOption("Require.verbose
a
}

## What Require itself downloads with: GETWauthThenNonAuth() through curl, which
## returns the curl_fetch_memory() list (status_code, content) instead of an httr
## response. GETWauthThenNonAuth() stays on httr for the SpaDES packages, which read
## its result with httr::content() and httr::stop_for_status().
curlGETauth <- function(url, token, verbose = getOption("Require.verbose")) {
a <- curlGET(url, token)
badCreds <- grepl("Bad credentials", rawToChar(a$content[a$content != as.raw(0)]))
if (badCreds || a$status_code == 404L) {
if (badCreds) messageVerbose(red("Git credentials do not work for this url: ", url,
"\nAre they expired?"), verbose = verbose)
a <- curlGET(url)
}
a
}

## One GET, in memory, with the token (if any) as the Authorization header. As before,
## an HTTP error status is returned, not raised; a connection failure is an error.
curlGET <- function(url, token = NULL) {
h <- curl::new_handle()
if (!is.null(token))
curl::handle_setheaders(h, Authorization = token)
curl::curl_fetch_memory(url, h)
}



available.packagesWithCallingHandlers <- function(repo, type, verbose = getOption("Require.verbose")) {
Expand Down Expand Up @@ -1731,7 +1749,7 @@ readLinesWithHandlers <- function(fff) {
)
}

# if (grepl("404", httr::http_status(a)$message)) {
# if (a$status_code == 404L) {
# offerGitHubSuggestions(account, repo)
# stop("The following repository does not seem to exist: \n",
# paste(pkgDTNotLocal$packageFullName[has404], collapse = "\n"),
Expand Down Expand Up @@ -1792,7 +1810,7 @@ apiGithubDotCom <- "https://api.github.com"
checkForToken <- function() {
token <- NULL
usesGitCreds <- requireNamespace("gitcreds", quietly = TRUE) &&
requireNamespace("httr", quietly = TRUE)
requireNamespace("curl", quietly = TRUE)
if (usesGitCreds) {
token <- getGitCredsToken()
}
Expand Down
15 changes: 13 additions & 2 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ setup <- function(newLibPaths,
return(invisible())
}

# The closest directory, from `start` up to the file-system root, that holds a `*.Rproj`
# file (an RStudio project); NULL if there is none.
findRprojDir <- function(start = getwd()) {
d <- normalizePath(start, winslash = "/", mustWork = FALSE)
repeat {
if (length(list.files(d, pattern = "\\.Rproj$")) > 0) return(d)
parent <- dirname(d)
if (identical(parent, d)) return(NULL)
d <- parent
}
}

#' @rdname setup
#' @inheritParams Require
#' @export
Expand All @@ -295,8 +307,7 @@ setupOff <- function(removePackages = FALSE, verbose = getOption("Require.verbos
updateRprofile <- checkTRUERprofile(TRUE)
if (!file.exists(updateRprofile)) { # not in current dir
## 1. Check project
# find_root() stops when the working directory is not in an RStudio project
possDirs <- c(tryCatch(rprojroot::find_root(rprojroot::is_rstudio_project), error = function(e) NULL), "~")
possDirs <- c(findRprojDir(), "~")
for (possDir in possDirs) {
possFile <- file.path(possDir, updateRprofile)
if (file.exists(possFile)) {
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-04other_testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ test_that("test 4", {
pkgs <- c("fpCompare", "rlang", "cli", "crayon", "stringr", "lobstr")
a <- unique(extractPkgName(unlist(unname(pkgDep(pkgs)))))
cacheClearPackages(a, ask = FALSE)
library(waldo)
setLibPaths(tempdir3())
try(remove.packages(a))
options(Require.installPackagesSys = 1L)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-14coverage2_testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ test_that("setup() deprecated emits a deprecation warning", {

test_that("setupOff() with no .Rprofile just messages", {
td <- tempdir2("setupOffNoRprofile")
# Create a minimal .Rproj so rprojroot::find_root doesn't error
# a project folder, so findRprojDir() finds td
writeLines("Version: 1.0\n", file.path(td, "test.Rproj"))
origDir <- setwd(td)
on.exit(setwd(origDir), add = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-15bugfixes_testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ test_that("Require.downloadTimeout raises options(timeout) during GH download (i
oldTimeout <- getOption("timeout")
observed <- NULL
# Force a token-less code path (the `download.file` branch) by ensuring
# checkForToken() returns NULL. Tokens go through httr::GET instead.
# checkForToken() returns NULL. Tokens go through curl instead.
withr::with_options(
list(
Require.downloadTimeout = 1234L,
Expand Down
Loading