Type: | Package |
Title: | Load Configuration Values |
Version: | 0.0.2 |
Description: | A simple approach to configuring R projects with different parameter values. Configurations are specified using a reduced subset of base R and parsed accordingly. |
URL: | https://timtaylor.codeberg.page/ronfig/ |
BugReports: | https://codeberg.org/TimTaylor/ronfig/issues |
License: | GPL-2 | GPL-3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.3 |
Imports: | cli, utils |
Suggests: | litedown, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
VignetteBuilder: | litedown |
NeedsCompilation: | no |
Packaged: | 2025-09-10 09:44:53 UTC; tim |
Author: | Tim Taylor |
Maintainer: | Tim Taylor <tim.taylor@hiddenelephants.co.uk> |
Repository: | CRAN |
Date/Publication: | 2025-09-15 08:30:02 UTC |
Load configuration
Description
Load a user defined configuration from file. By default
(i.e. when as_is = FALSE
), load_config()
requires inputs to be given as
uniquely-named lists. It first parses the configuration file looking for a
'default' entry. With no additional arguments this will be returned as a list
to the user. If the user specifies an additional list to consider (via the
config
argument) then this list is layered on top
(using utils::modifyList()
).
Usage
load_config(filename, config, ..., as_is = FALSE, default = "default")
Arguments
filename |
Configuration file to read from. |
config |
Name of entry in configuration file to layer on top of 'default'. Not used if |
... |
Not currently used. |
as_is |
Should the configuration file be read in as is, without layering on top of
the Defaults to |
default |
The default configuration to use. |
Details
Configuration files can be specified using a reduced subset of base R. Currently this is restricted to the following operators and functions:
<-, =, +, -, *, :,
as.Date (for character inputs),
array, matrix,
list, data.frame,
c,
length,
seq (for numeric and date inputs),
sequence (for numeric inputs),
seq_len, seq_along,
Sys.Date and Sys.time.
We also enable a convenience function, cc
, which automatically quotes input
to save typing.
Value
If as_is = FALSE
(default) a list contain entries corresponding to the
chosen config
. If as_is = TRUE
, a list of all entries in the evaluated
configuration file.
Examples
# load the example configuration
file <- system.file("config.R", package = "ronfig")
cat(readChar(file, file.info(file)$size))
# default configuration
str(load_config(file))
# debug configuration
str(load_config(file, "debug"))
# forecast configuration
str(load_config(file, "forecast"))