Convert a highlighted vector x
(class vlightr_highlight
) into a highlighter
function (class vlightr_highligher
) which applies the same conditional
formatting as that of x
.
Arguments
- x
[vlightr_highlight]
A highlighted vector to convert to a highlighter (class
vlightr_highlighter
) function. Seehighlighter()
for details.
Value
A highlighter function with the same conditions
, formatters
, description
,
precedence
, format_once
, init_formatter
, and last_formatter
as x
.
Examples
# Highlight a vector
dummy <- highlight_case(
x = c(1L, NA, 0L, 1L, NA),
.x == 0 ~ paste0(.x, "[No]"),
.x == 1 ~ paste0(.x, "[Yes]"),
is.na ~ cli::col_red,
.description = c(
"Responded No",
"Responded Yes",
"No Response"
)
)
#> Error in highlight_case(x = c(1L, NA, 0L, 1L, NA), .x == 0 ~ paste0(.x, "[No]"), .x == 1 ~ paste0(.x, "[Yes]"), is.na ~ cli::col_red, .description = c("Responded No", "Responded Yes", "No Response")): `.x` must be a non-bare-list and non-dataframe vector, not a <formula>
#> object.
#> ℹ See `?vctrs::obj_is_vector()` for details on vectors.
print(dummy)
#> Error: object 'dummy' not found
describe_highlight(dummy)
#> Error in describe_highlight(dummy): could not find function "describe_highlight"
# Convert the highlighted vector into a highlighter function
dummy_hlghtr <- as_highlighter(dummy)
#> Error: object 'dummy' not found
print(dummy_hlghtr(c(0L, 1L, NA, 2L)))
#> Error in dummy_hlghtr(c(0L, 1L, NA, 2L)): could not find function "dummy_hlghtr"
describe_highlight(dummy_hlghtr(c(0L, 1L, NA, 2L)))
#> Error in describe_highlight(dummy_hlghtr(c(0L, 1L, NA, 2L))): could not find function "describe_highlight"