| Type: | Package | 
| Title: | Load Configuration Values | 
| Version: | 0.0.5 | 
| 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: | carrier, cli, utils | 
| Suggests: | knitr, quarto, testthat (≥ 3.0.0) | 
| Config/testthat/edition: | 3 | 
| VignetteBuilder: | quarto | 
| NeedsCompilation: | no | 
| Packaged: | 2025-10-14 09:28:22 UTC; tim | 
| Author: | Tim Taylor | 
| Maintainer: | Tim Taylor <tim.taylor@hiddenelephants.co.uk> | 
| Repository: | CRAN | 
| Date/Publication: | 2025-10-14 09:50: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, crates, ..., 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  | 
| crates | A list of carrier::crate objects which are used to inject functions in to the environment where the configuration file will be evaluated. | 
| ... | 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. By defauly this is restricted to the following operators and functions:
- <-, =, +, -, *, :, 
- $, [, [[, 
- $<-, [<-, [[<-, 
- c, 
- as.Date, 
- array, matrix, 
- list, data.frame, 
- Sys.Date, Sys.time, 
- seq, sequence and seq_len. 
- file.path 
We also enable a convenience function, cc, which automatically quotes input
to save typing.
Users can also inject their own functions in to the evaluation environment by supplying a list of crates as an additional argument.
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"))
# Injecting crated function
f <- tempfile()
cat("default <- list(a=mean(1:10))", file = f)
# will fail as mean() not available
tryCatch(with(load_config(f), a), error = conditionMessage)
# will work if we inject crated mean
crate <- carrier::crate(function(x) mean(x))
with(load_config(f, crates = list(mean = crate)), a)
unlink(f)