-- L --
load_config()
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()
).
load_config(filename, config, ..., as_is = FALSE, default = "default")
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. |
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.
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.
# load the example configuration
file <- system.file("config.R", package = "ronfig")
cat(readChar(file, file.info(file)$size))
#> # This is our default configuration which must be a named list
#> # All other changes are layered on top of this.
#> default <- list(
#> date = as.Date("2025-09-02"),
#> N = 1000,
#> alpha = 0.3,
#> gamma = 0.2,
#> beta = 0.7,
#> max_delay = 30,
#> years = 2006:2025
#> )
#>
#> # You may need to debug some results and wish to set one parameter to 0 and only
#> # look at a reduced number of years, e.g.
#> debug <- list(
#> years = 2024:2025,
#> alpha = 0
#> )
#>
#> # Or you may wish to consider an extended range of years
#> forecast <- list(
#> years = 2006:2030
#> )
# default configuration
str(load_config(file))
#> List of 7
#> $ date : Date[1:1], format: "2025-09-02"
#> $ N : num 1000
#> $ alpha : num 0.3
#> $ gamma : num 0.2
#> $ beta : num 0.7
#> $ max_delay: num 30
#> $ years : int [1:20] 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 ...
# debug configuration
str(load_config(file, "debug"))
#> List of 7
#> $ date : Date[1:1], format: "2025-09-02"
#> $ N : num 1000
#> $ alpha : num 0
#> $ gamma : num 0.2
#> $ beta : num 0.7
#> $ max_delay: num 30
#> $ years : int [1:2] 2024 2025
# forecast configuration
str(load_config(file, "forecast"))
#> List of 7
#> $ date : Date[1:1], format: "2025-09-02"
#> $ N : num 1000
#> $ alpha : num 0.3
#> $ gamma : num 0.2
#> $ beta : num 0.7
#> $ max_delay: num 30
#> $ years : int [1:25] 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 ...