reon provides an R interface to the eon configuration format via extendr. eon is a human-friendly configuration format inspired by JSON, with optional commas, unquoted identifier keys, and support for comments.
// Analysis configuration
outcome: "vote_share"
predictors: ["income", "education", "age"]
model: {
family: "gaussian"
iterations: 2000
chains: 4
}
seed: 1234
Installation
You can install the development version of reon from GitHub with:
# install.packages("pak")
pak::pak("christopherkenny/reon")Usage
Writing eon
Convert an R list to an eon-formatted string:
l <- list(
outcome = 'vote_share',
predictors = list('income', 'education', 'age'),
model = list(family = 'gaussian', iterations = 2000L, chains = 4L),
seed = 1234L
)
cat(format_eon(l))
#> outcome: "vote_share"
#> predictors: ["income", "education", "age"]
#> model: {
#> family: "gaussian"
#> iterations: 2000
#> chains: 4
#> }
#> seed: 1234Write to a file with write_eon():
Reading eon
Read an eon file back into R:
read_eon(tmp)
#> $outcome
#> [1] "vote_share"
#>
#> $predictors
#> $predictors[[1]]
#> [1] "income"
#>
#> $predictors[[2]]
#> [1] "education"
#>
#> $predictors[[3]]
#> [1] "age"
#>
#>
#> $model
#> $model$family
#> [1] "gaussian"
#>
#> $model$iterations
#> [1] 2000
#>
#> $model$chains
#> [1] 4
#>
#>
#> $seed
#> [1] 1234Or parse an eon string directly:
parse_eon(
'
outcome: "vote_share"
predictors: ["income", "education", "age"]
model: { family: "gaussian", iterations: 2000, chains: 4 }
seed: 1234
'
)
#> $outcome
#> [1] "vote_share"
#>
#> $predictors
#> $predictors[[1]]
#> [1] "income"
#>
#> $predictors[[2]]
#> [1] "education"
#>
#> $predictors[[3]]
#> [1] "age"
#>
#>
#> $model
#> $model$family
#> [1] "gaussian"
#>
#> $model$iterations
#> [1] 2000
#>
#> $model$chains
#> [1] 4
#>
#>
#> $seed
#> [1] 1234Reformatting
Normalize the style of an existing eon string without changing its data:
reformat_eon('{outcome:"vote_share",seed:1234,chains:4}')
#> [1] "outcome: \"vote_share\"\nseed: 1234\nchains: 4\n"Type mapping
| R type | eon type |
|---|---|
NULL |
null |
logical(1) |
boolean |
integer(1) |
integer |
double(1) |
float |
character(1) |
string |
named list
|
map { }
|
unnamed list
|
list [ ]
|
NA |
null |
Inf / -Inf
|
+inf / -inf
|
NaN |
+nan |
