-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0825c03
commit efe90f7
Showing
24 changed files
with
604 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,8 @@ Suggests: | |
rmarkdown, | ||
crul, | ||
Rarr, | ||
vcr (>= 0.6.0) | ||
vcr (>= 0.6.0), | ||
pbapply, | ||
parallel, | ||
future, | ||
bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#' @keywords internal | ||
.onLoad <- function(libname = NULL, pkgname = NULL) { | ||
init_options() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Adapted from https://github.com/IRkernel/IRkernel/blob/master/R/options.r | ||
|
||
#' pizzarr_option_defaults | ||
#' @export | ||
pizzarr_option_defaults <- list( | ||
pizzarr.http_store_cache_time_seconds = 3600, | ||
pizzarr.parallel_read_enabled = FALSE, | ||
pizzarr.parallel_write_enabled = FALSE | ||
) | ||
|
||
#' @keywords internal | ||
parse_parallel_option <- function(val) { | ||
if(val == "future") { | ||
return("future") | ||
} | ||
logical_val <- suppressWarnings(as.logical(val)) | ||
integer_val <- suppressWarnings(as.integer(val)) | ||
|
||
if(is.na(integer_val)) { | ||
return(logical_val) | ||
} | ||
if(integer_val <= 1) { | ||
return(as.logical(integer_val)) | ||
} | ||
return(integer_val) | ||
} | ||
|
||
#' @keywords internal | ||
from_env <- list( | ||
PIZZARR_HTTP_STORE_CACHE_TIME_SECONDS = as.integer, | ||
PIZZARR_PARALLEL_READ_ENABLED = parse_parallel_option, | ||
PIZZARR_PARALLEL_WRITE_ENABLED = parse_parallel_option | ||
) | ||
|
||
# converts e.g. jupyter.log_level to JUPYTER_LOG_LEVEL | ||
#' @keywords internal | ||
opt_to_env <- function(nms) { | ||
gsub('.', '_', toupper(nms), fixed = TRUE) | ||
} | ||
|
||
# called in .onLoad | ||
#' @keywords internal | ||
init_options <- function() { | ||
for (opt_name in names(pizzarr_option_defaults)) { | ||
# skip option if it is already set, e.g. in the Rprofile | ||
if (is.null(getOption(opt_name))) { | ||
# prepare `options` call from the default | ||
call_arg <- pizzarr_option_defaults[opt_name] # single [] preserve names | ||
|
||
# if an env var is set, get value from it. | ||
env_name <- opt_to_env(opt_name) | ||
convert <- from_env[[env_name]] | ||
env_val <- Sys.getenv(env_name, unset = NA) | ||
if (!is.null(convert) && !is.na(env_val)) { | ||
call_arg[[opt_name]] <- convert(env_val) | ||
} | ||
|
||
do.call(options, call_arg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.