Skip to content

Commit

Permalink
Merge pull request #107 from LibraryCarpentry/update/packages
Browse files Browse the repository at this point in the history
Update 4 packages
  • Loading branch information
jt14den authored Jan 28, 2025
2 parents 2e9ebe0 + f286732 commit 59b673b
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 11 deletions.
103 changes: 94 additions & 9 deletions renv/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,66 @@ local({
unloadNamespace("renv")

# load bootstrap tools
ansify <- function(text) {
if (renv_ansify_enabled())
renv_ansify_enhanced(text)
else
renv_ansify_default(text)
}

renv_ansify_enabled <- function() {

override <- Sys.getenv("RENV_ANSIFY_ENABLED", unset = NA)
if (!is.na(override))
return(as.logical(override))

pane <- Sys.getenv("RSTUDIO_CHILD_PROCESS_PANE", unset = NA)
if (identical(pane, "build"))
return(FALSE)

testthat <- Sys.getenv("TESTTHAT", unset = "false")
if (tolower(testthat) %in% "true")
return(FALSE)

iderun <- Sys.getenv("R_CLI_HAS_HYPERLINK_IDE_RUN", unset = "false")
if (tolower(iderun) %in% "false")
return(FALSE)

TRUE

}

renv_ansify_default <- function(text) {
text
}

renv_ansify_enhanced <- function(text) {

# R help links
pattern <- "`\\?(renv::(?:[^`])+)`"
replacement <- "`\033]8;;ide:help:\\1\a?\\1\033]8;;\a`"
text <- gsub(pattern, replacement, text, perl = TRUE)

# runnable code
pattern <- "`(renv::(?:[^`])+)`"
replacement <- "`\033]8;;ide:run:\\1\a\\1\033]8;;\a`"
text <- gsub(pattern, replacement, text, perl = TRUE)

# return ansified text
text

}

renv_ansify_init <- function() {

envir <- renv_envir_self()
if (renv_ansify_enabled())
assign("ansify", renv_ansify_enhanced, envir = envir)
else
assign("ansify", renv_ansify_default, envir = envir)

}

`%||%` <- function(x, y) {
if (is.null(x)) y else x
}
Expand Down Expand Up @@ -142,7 +202,10 @@ local({
# compute common indent
indent <- regexpr("[^[:space:]]", lines)
common <- min(setdiff(indent, -1L)) - leave
paste(substring(lines, common), collapse = "\n")
text <- paste(substring(lines, common), collapse = "\n")

# substitute in ANSI links for executable renv code
ansify(text)

}

Expand Down Expand Up @@ -305,8 +368,11 @@ local({
quiet = TRUE
)

if ("headers" %in% names(formals(utils::download.file)))
args$headers <- renv_bootstrap_download_custom_headers(url)
if ("headers" %in% names(formals(utils::download.file))) {
headers <- renv_bootstrap_download_custom_headers(url)
if (length(headers) && is.character(headers))
args$headers <- headers
}

do.call(utils::download.file, args)

Expand Down Expand Up @@ -385,10 +451,21 @@ local({
for (type in types) {
for (repos in renv_bootstrap_repos()) {

# build arguments for utils::available.packages() call
args <- list(type = type, repos = repos)

# add custom headers if available -- note that
# utils::available.packages() will pass this to download.file()
if ("headers" %in% names(formals(utils::download.file))) {
headers <- renv_bootstrap_download_custom_headers(repos)
if (length(headers) && is.character(headers))
args$headers <- headers
}

# retrieve package database
db <- tryCatch(
as.data.frame(
utils::available.packages(type = type, repos = repos),
do.call(utils::available.packages, args),
stringsAsFactors = FALSE
),
error = identity
Expand Down Expand Up @@ -470,23 +547,31 @@ local({

}

renv_bootstrap_github_token <- function() {
for (envvar in c("GITHUB_TOKEN", "GITHUB_PAT", "GH_TOKEN")) {
envval <- Sys.getenv(envvar, unset = NA)
if (!is.na(envval))
return(envval)
}
}

renv_bootstrap_download_github <- function(version) {

enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE")
if (!identical(enabled, "TRUE"))
return(FALSE)

# prepare download options
pat <- Sys.getenv("GITHUB_PAT")
if (nzchar(Sys.which("curl")) && nzchar(pat)) {
token <- renv_bootstrap_github_token()
if (nzchar(Sys.which("curl")) && nzchar(token)) {
fmt <- "--location --fail --header \"Authorization: token %s\""
extra <- sprintf(fmt, pat)
extra <- sprintf(fmt, token)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "curl", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
} else if (nzchar(Sys.which("wget")) && nzchar(pat)) {
} else if (nzchar(Sys.which("wget")) && nzchar(token)) {
fmt <- "--header=\"Authorization: token %s\""
extra <- sprintf(fmt, pat)
extra <- sprintf(fmt, token)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "wget", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
Expand Down
13 changes: 11 additions & 2 deletions renv/profiles/lesson-requirements/renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@
"Package": "lattice",
"Version": "0.22-6",
"Source": "Repository",
"Repository": "CRAN",
"Repository": "RSPM",
"Requirements": [
"R",
"grDevices",
Expand Down Expand Up @@ -991,6 +991,9 @@
"Version": "1.3.3",
"Source": "Repository",
"Repository": "https://carpentries.r-universe.dev",
"RemoteUrl": "https://github.com/r-lib/ragg",
"RemoteRef": "v1.3.3",
"RemoteSha": "6f2279ae8cd0e0d7e9d0e1ede2b742666f9f1d49",
"Requirements": [
"systemfonts",
"textshaping"
Expand Down Expand Up @@ -1195,7 +1198,7 @@
"Package": "stringi",
"Version": "1.8.4",
"Source": "Repository",
"Repository": "carpentries",
"Repository": "RSPM",
"Requirements": [
"R",
"stats",
Expand Down Expand Up @@ -1233,6 +1236,9 @@
"Version": "1.1.0",
"Source": "Repository",
"Repository": "https://carpentries.r-universe.dev",
"RemoteUrl": "https://github.com/r-lib/systemfonts",
"RemoteRef": "v1.1.0",
"RemoteSha": "78df90ca6d869feeb6a40c88f72269093505aa22",
"Requirements": [
"R",
"cpp11",
Expand Down Expand Up @@ -1483,6 +1489,9 @@
"Version": "1.3.6",
"Source": "Repository",
"Repository": "https://carpentries.r-universe.dev",
"RemoteUrl": "https://github.com/r-lib/xml2",
"RemoteRef": "v1.3.6",
"RemoteSha": "6a1b5e8fd44601faffcd5c56b6837bbf6ee41322",
"Requirements": [
"R",
"cli",
Expand Down

0 comments on commit 59b673b

Please sign in to comment.