The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
The config
package makes it easy to manage environment
specific configuration values. For example, you might want to use
distinct values for development, testing, and production
environments.
Configurations are defined using a YAML text file and are read by default from a file named config.yml in the current working directory (or parent directories if no config file is found in the initially specified directory).
Configuration files include default values as well as values for arbitrary other named configurations, for example:
config.yml
To read configuration values you call the config::get
function, which returns a list containing all of the values for the
currently active configuration:
R
## [1] 5
## [1] "data-sampled.csv"
You can also read a single value from the configuration as follows:
R
## [1] 5
## [1] "data-sampled.csv"
The get
function takes an optional config
argument which determines which configuration to read values from (the
“default” configuration is used if none is specified).
You can specify which configuration is currently active by setting
the R_CONFIG_ACTIVE
environment variable. The
R_CONFIG_ACTIVE
variable is typically set within a
site-wide Renviron
or Rprofile
(see R
Startup for details on these files).
R
# set the active configuration globally via Renviron.site or Rprofile.site
Sys.setenv(R_CONFIG_ACTIVE = "production")
# read configuration value (will return 30 from the "production" config)
config::get("trials")
## [1] 30
You can check whether a particular configuration is active using the
config::is_active
function:
R
## [1] TRUE
R
By default configuration data is read from a file named config.yml within the current working directory (or parent directories if no config file is found in the initially specified directory).
You can use the file
argument of
config::get
to read from an alternate location. For
example:
R
If you don’t want to ever scan parent directories for configuration
files then you can specify use_parent = FALSE
:
R
libary(config)
We strongly recommend you use config::get()
rather than
attaching the package using library(config)
.
In fact, we strongly recommend you never use
library(config)
.
The underlying reason is that the get()
and
merge()
functions in {config}
will mask these
functions with the same names in base R.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.