Get, set, and check persistent preference values for 'RAVE' pipelines and modules. Preferences are stored in a global on-disk store that survives across R sessions.
Usage
pipeline_set_preferences(
...,
.list = NULL,
.pipe_dir = Sys.getenv("RAVE_PIPELINE", "."),
.preference_instance = NULL
)
pipeline_get_preferences(
keys,
simplify = TRUE,
ifnotfound = NULL,
validator = NULL,
modes = NULL,
...,
.preference_instance = NULL
)
pipeline_has_preferences(keys, ..., .preference_instance = NULL)Arguments
- ..., .list
for
pipeline_set_preferences: named values to store, where each name is a preference key; forpipeline_get_preferences: additional arguments forwarded tovalidator- .pipe_dir
the active pipeline directory used to determine the allowed key prefix; defaults to the
RAVE_PIPELINEenvironment variable or the current working directory- .preference_instance
pipeline preference instance: this is automatically filled when calling from
pipeline$get_preferences()WhenNULL, the shared on-disk preference store is used automatically- keys
one or more preference key strings following the
[prefix].[type].[key]naming convention- simplify
if
TRUE(default) and exactly one key is requested, return the value directly instead of a length-one named list- ifnotfound
value returned when a requested key is absent or fails validation; default is
NULL- validator
NULLor a single-argument function that validates each retrieved value; any extra arguments in...are forwarded to it. If the function signals an error,ifnotfoundis returned for that key instead- modes
NULL, or a character vector of expected Rmodestrings (e.g."numeric","character") recycled to match the length ofkeys. A stored value whose mode does not match is treated as missing and replaced byifnotfound
Value
pipeline_set_preferencesInvisibly returns the named list of values that were passed in.
pipeline_get_preferencesThe preference value(s): a single value when
simplify = TRUEand one key is requested, otherwise a named list with one element per key.pipeline_has_preferencesA logical vector the same length as
keysindicating which keys currently exist in the preference store.
Details
Preference keys must follow a three-part dot-separated naming convention
[prefix].[type].[key]:
prefixEither
"global"(shared across all modules) or a specific module ID such as"power_explorer". When callingpipeline_set_preferencesfrom within a pipeline, the allowed prefixes are automatically restricted to"global"and the current pipeline name.typeA category string such as
"graphics"or"export".keyThe individual preference item, e.g.
"use_ggplot"or"default_format".
Valid examples: "global.graphics.use_ggplot",
"power_explorer.export.default_format".
Setting a preference value to NULL removes the key from the store.
Examples
if (FALSE) { # \dontrun{
# Set preferences (keys use [prefix].[type].[key] convention)
pipeline_set_preferences(
"global.graphics.use_ggplot" = TRUE,
"global.graphics.cex" = 1.2
)
# Check whether keys exist
pipeline_has_preferences(
c("global.graphics.use_ggplot", "global.graphics.cex")
)
# Retrieve a single preference (returns the value directly)
pipeline_get_preferences("global.graphics.cex")
# Retrieve multiple preferences as a named list
pipeline_get_preferences(
keys = c("global.graphics.use_ggplot", "global.graphics.cex"),
simplify = FALSE
)
# Return a default when the key is absent
pipeline_get_preferences("global.graphics.missing_key", ifnotfound = FALSE)
# Validate the stored mode; fall back to default on mismatch
pipeline_get_preferences(
"global.graphics.cex",
modes = "numeric",
ifnotfound = 1.0
)
# Remove a preference by setting it to NULL
pipeline_set_preferences("global.graphics.cex" = NULL)
} # }