<- c(1, 4, 5, 8, 12, 20, 0, -5, 1.3, NA) num_vals
The vec_fmt_roman()
function
Let’s create a numeric vector for the next few examples:
Using vec_fmt_roman()
with the default options will create a character vector with values rendered as Roman numerals. Zero values will be rendered as "N"
, any NA
values remain as NA
values, negative values will be automatically made positive, and values greater than or equal to 3900 will be rendered as "ex terminis"
. The rendering context will be autodetected unless specified in the output
argument (here, it is of the "plain"
output type).
vec_fmt_roman(num_vals)
[1] "I" "IV" "V" "VIII" "XII" "XX" "N" "V" "I" "NA"
#> [1] "I" "IV" "V" "VIII" "XII" "XX" "N" "V" "I" "NA"
We can also use vec_fmt_roman()
with the case = "lower"
option to create a character vector with values rendered as lowercase Roman numerals.
vec_fmt_roman(num_vals, case = "lower")
[1] "i" "iv" "v" "viii" "xii" "xx" "n" "v" "i" "NA"
#> [1] "i" "iv" "v" "viii" "xii" "xx" "n" "v" "i" "NA"
As a last example, one can wrap the values in a pattern with the pattern
argument. Note here that NA
values won’t have the pattern applied.
vec_fmt_roman(num_vals, case = "lower", pattern = "{x}.")
[1] "i." "iv." "v." "viii." "xii." "xx." "n." "v." "i."
[10] "NA"
#> [1] "i." "iv." "v." "viii." "xii." "xx." "n." "v." "i." "NA"