Style a Vector with Text Formatting
Usage
style_vector(
x,
output = "html",
bold = FALSE,
italic = FALSE,
monospace = FALSE,
smallcap = FALSE,
underline = FALSE,
strikeout = FALSE,
color = NULL,
fontsize = NULL,
indent = NULL
)Arguments
- x
A vector to be styled.
- output
Output format for styling. One of "html", "latex", "typst", "markdown", "ansi". Defaults to "html".
- bold
Logical; if
TRUE, text is styled in bold. Must be of length 1 orlength(x).- italic
Logical; if
TRUE, text is styled in italic. Must be of length 1 orlength(x).- monospace
Logical; if
TRUE, text is styled in monospace font. Must be of length 1 orlength(x).- smallcap
Logical; if
TRUE, text is styled in small caps. In Markdown output format, text is converted to uppercase. Must be of length 1 orlength(x).- underline
Logical; if
TRUE, text is underlined. Must be of length 1 orlength(x).- strikeout
Logical; if
TRUE, text has a strike through line. Must be of length 1 orlength(x).- color
Text color. Must be of length 1 or
length(x). There are several ways to specify colors:HTML:
Hex code composed of # and 6 characters, ex: #CC79A7.
Keywords: black, silver, gray, white, maroon, red, purple, fuchsia, green, lime, olive, yellow, navy, blue, teal, aqua
LaTeX:
Hex code composed of # and 6 characters, ex: "#CC79A7".
Keywords: black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta, olive, orange, pink, purple, red, teal, violet, white, yellow.
Color blending using xcolor, ex:
white!80!blue,green!20!red.Color names with luminance levels from the
ninecolorspackage.
- fontsize
Font size in em units. Must be of length 1 or
length(x). Can beNULLfor default size.- indent
Text indentation in em units. Must be of length 1 or
length(x). Positive values only.
Details
This function applies styling to a vector. It allows customization of text style (bold, italic, monospace), text color, font size, and text decorations (underline, strikeout). The styling is applied element-wise to the vector. Vectors are coerced with as.character() before styling.
Examples
# Basic styling
style_vector(c("Hello", "World"), bold = TRUE, color = "red")
#> [1] "<b><span style='color:#FF0000'>Hello</span></b>"
#> [2] "<b><span style='color:#FF0000'>World</span></b>"
# Different styles per element
style_vector(
c("Bold text", "Italic text", "Monospace"),
bold = c(TRUE, FALSE, FALSE),
italic = c(FALSE, TRUE, FALSE),
monospace = c(FALSE, FALSE, TRUE)
)
#> [1] "<b>Bold text</b>" "<i>Italic text</i>" "<code>Monospace</code>"
# Single style applied to all elements
style_vector(c("A", "B", "C"), color = "blue", fontsize = 1.2)
#> [1] "<span style='color:#0000FF; font-size:1.2em'>A</span>"
#> [2] "<span style='color:#0000FF; font-size:1.2em'>B</span>"
#> [3] "<span style='color:#0000FF; font-size:1.2em'>C</span>"