Debian Codegraph @

R/options.r

raw symbols SCIP
1 #' @usage
2 #' jupyter_option_defaults
3 #'
4 #' @rdname IRkernel-package
5 #' @export
6 jupyter_option_defaults <- list(
7 jupyter.rich_display = TRUE, # moved from IRdisplay
8 jupyter.log_level = 1L,
9 jupyter.logfile = NA,
10 jupyter.pager_classes = c(
11 'packageIQR',
12 'help_files_with_topic'),
13 jupyter.plot_mimetypes = c(
14 'text/plain',
15 'image/png'),
16 jupyter.plot_scale = 2,
17 jupyter.in_kernel = FALSE)
18
19 from_env <- list(
20 JUPYTER_LOG_LEVEL = as.integer,
21 JUPYTER_LOGFILE = function(f) if (nchar(f) == 0) NA else f)
22
23 # converts e.g. jupyter.log_level to JUPYTER_LOG_LEVEL
24 opt_to_env <- function(nms) gsub('.', '_', toupper(nms), fixed = TRUE)
25
26 # called in .onLoad
27 init_options <- function() {
28 for (opt_name in names(jupyter_option_defaults)) {
29 # skip option if it is already set, e.g. in the Rprofile
30 if (is.null(getOption(opt_name))) {
31 # prepare `options` call from the default
32 call_arg <- jupyter_option_defaults[opt_name] # single [] preserve names
33
34 # if an env var is set, get value from it.
35 env_name <- opt_to_env(opt_name)
36 convert <- from_env[[env_name]]
37 env_val <- Sys.getenv(env_name, unset = NA)
38 if (!is.null(convert) && !is.na(env_val))
39 call_arg[[opt_name]] <- convert(env_val)
40
41 do.call(options, call_arg)
42 }
43 }
44 }