A wrapper around validated_reactive_val()
to help manage factor-like
values, especially in a cascading / dependent manner. This is a convenience
function that constructs the validation_expr
for you by wrapping
stbl::stabilize_fct()
. Note that the objects returned by the resulting
vrv
are character
vectors, not factor
s, to allow values to remain
unchanged when the allowed levels change but the value is still valid.
Usage
vrv_fct(
levels,
value = NULL,
default = NULL,
allow_null = TRUE,
allow_na = TRUE,
min_size = NULL,
max_size = NULL,
to_na = character(),
label = NULL,
env = rlang::caller_env()
)
vrv_fct_scalar(
levels,
value = NULL,
default = NULL,
allow_null = TRUE,
allow_zero_length = TRUE,
allow_na = TRUE,
to_na = character(),
label = NULL,
env = rlang::caller_env()
)
Arguments
- levels
(
expression
) An expression that returns acharacter
vector of valid levels. Can be a reactive expression.- value
(various) The initial value. This value will be coerced via the validation expression when accessed. If this value is reactive, an observer with
priority = Inf
will be created to attempt to keep the validated value in sync with that reactive.- default
(various, including
expression
orreactive expression
) A value to use when the current value is not valid according to the defined rules. Defaults toNULL
.- allow_null
(length-1
logical
,expression
, orreactive expression
) IsNULL
an acceptable value?- allow_na
(length-1
logical
,expression
, orreactive expression
) AreNA
values okay?- min_size
(length-1
integer
,expression
, orreactive expression
) The minimum size of the vector.- max_size
(length-1
integer
,expression
, orreactive expression
) The maximum size of the vector.- to_na
(
expression
) Values to coerce toNA
. Can be a reactive expression.- label
(length-1
character
orNULL
) An optional label for thevalidated_reactive_value
, used for debugging.- env
(
environment
) The environment in which to evaluate thevalidation_expr
.- allow_zero_length
(
expression
) Is a zero-length vector acceptable? Can be a reactive expression.