Sometimes, the analyst wants to run an R script from the
shell and override a few configuration values at runtime, without
editing YAML files. They may also want a multi-run call that executes
the same script over a grid of configuration parameters.
This workflow can be achieved using Rscript and the
hydraR::main() function.
Minimal example
When you only need one run with default parameters, a minimal config
and a single Rscript call keep things simple and
reproducible.
The full minimal.yml used in this example is:
The example.R script executed by Rscript
is:
#!/usr/bin/env Rscript
square <- function(cfg) {
x <- cfg$numeric
out <- sprintf("Input=%s -> Square=%s", x, x^2)
print(out)
}
hydraR::main(
square,
config_path = "/path/to/config/",
config_name = "minimal"
)Run the script once with no command-line overrides:
The printed output is:
Config override
When one script needs to run against different config folders or file names, you can switch both from the command line without editing the script itself.
Parameter override
A common workflow is to keep a stable base config and override just one value from the shell for quick experiments.
Using the same minimal config as before, we can do a
single parameter override:
The printed output is:
Multi-parameter sweep
When you want to evaluate multiple values in one command, multi-run sweeps avoid manual repetition and keep runs consistent.
Run a sweep with -m across three values, separated by
commas:
The printed output is:
Global options
If many functions share the same config, setting
hydraR.main.* options lets you avoid repeating
config_path and config_name on every call.
The example.R script executed by Rscript
is:
#!/usr/bin/env Rscript
options(
hydraR.main.config_path = "/path/to/config/",
hydraR.main.config_name = "minimal"
)
square <- function(cfg) {
x <- cfg$numeric
out <- sprintf("Input=%s -> Square=%s", x, x^2)
print(out)
}
cube <- function(cfg) {
x <- cfg$numeric
out <- sprintf("Input=%s -> Square=%s", x, x^3)
print(out)
}
hydraR::main(square)
hydraR::main(cube)