Specialized validator for fraction/proportion values.
Usage
validate_fraction(
value,
param_name,
strategy = "strict",
allow_zero = TRUE,
allow_one = TRUE
)Value
An object of class fb4_validation (see
validation_result). valid is TRUE when all
values lie within \([0, 1]\) (or the bounds set by allow_zero
and allow_one). Out-of-range values are recorded in
errors (strategy "strict") or warnings
(strategy "warn").
Examples
validate_fraction(0.5, "diet_proportion")
#> $valid
#> [1] TRUE
#>
#> $errors
#> character(0)
#>
#> $warnings
#> character(0)
#>
#> $info
#> character(0)
#>
#> $level
#> [1] "combined"
#>
#> $category
#> NULL
#>
#> $checked_items
#> $checked_items$param_name
#> [1] "diet_proportion"
#>
#> $checked_items$type
#> [1] "numeric"
#>
#> $checked_items$length
#> [1] 1
#>
#> $checked_items$has_na
#> [1] FALSE
#>
#> $checked_items$has_infinite
#> [1] FALSE
#>
#> $checked_items$range_checked
#> [1] TRUE
#>
#>
#> $timestamp
#> [1] "2026-06-10 23:20:59 -04"
#>
#> attr(,"class")
#> [1] "fb4_validation"
validate_fraction(c(0.3, 0.7), "fractions")
#> $valid
#> [1] TRUE
#>
#> $errors
#> character(0)
#>
#> $warnings
#> character(0)
#>
#> $info
#> character(0)
#>
#> $level
#> [1] "combined"
#>
#> $category
#> NULL
#>
#> $checked_items
#> $checked_items$param_name
#> [1] "fractions"
#>
#> $checked_items$type
#> [1] "numeric"
#>
#> $checked_items$length
#> [1] 2
#>
#> $checked_items$has_na
#> [1] FALSE
#>
#> $checked_items$has_infinite
#> [1] FALSE
#>
#> $checked_items$range_checked
#> [1] TRUE
#>
#>
#> $timestamp
#> [1] "2026-06-10 23:20:59 -04"
#>
#> attr(,"class")
#> [1] "fb4_validation"
