with_config | R Documentation |
This function takes inspiration from withr::with_envvar()
and may be useful
for testing purposes.
with_config(
config_yml,
code,
.active_config = c(R_CONFIG_ACTIVE = "default"),
.extra_env_vars = NULL
)
config_yml |
Either the path to a config file, or a character string representing a yaml configuration. |
code |
Code to execute in a temporary environment. |
.active_config |
Either a string representing a configuration, e.g.
|
.extra_env_vars |
Additional environment variables to set. |
The result of running the code
, after having temporarily set the
necessary environment variables.
yaml <- '
default:
db_name: dbase
databases:
db1: !expr paste0(db_name, "/one")
db2: !expr paste0(db_name, "/two")
staging:
staging_postfix: _staging
db_name: dbase
databases:
db1: !expr paste0(db_name, staging_postfix, "/one")
db2: !expr paste0(db_name, staging_postfix, "/two")
'
# Ensure that base::get() doesn't get masked, for tests on CRAN
get <- base::get
with_config(yaml, config::get() )
with_config(yaml, config::get("databases", config = "default") )
with_config(yaml, config::get("databases", config = "staging") )
config_file <- system.file("tests/testthat/config.yml", package = "config")
if (file.exists(config_file)) {
with_config(config_file, config::get())
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.