Skip to content

Commit

Permalink
make improvem,emnts of get_configs with list path supoports
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Feb 2, 2024
1 parent 614abfa commit 1aa7e0f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions R/context/set_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,27 @@ const get_config = function(name, default = NULL) {
if (!("configs" in ctx)) {
NULL;
} else {
const env = ctx$configs;
const result = env[[name]];
const path = strsplit(name, "$", fixed = TRUE);
const verbose = as.logical(getOption("verbose"));

result || default;
if (verbose) {
if (length(path) > 1) {
print(`get configuration from path: ${paste(path, sep = " -> ")}`);
} else {
print(`get configuation via a key: ${name}`);
}
}

let config = ctx$configs;

for(name in path) {
if (name in config) {
config = config[[name]];
} else {
return(default);
}
}

return(config || default);
}
}

0 comments on commit 1aa7e0f

Please sign in to comment.