Learn R Programming

tinytable (version 0.14.0)

style_vector: Style a Vector with Text Formatting

Description

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
)

Value

A character vector with applied styling.

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 or length(x).

italic

Logical; if TRUE, text is styled in italic. Must be of length 1 or length(x).

monospace

Logical; if TRUE, text is styled in monospace font. Must be of length 1 or length(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 or length(x).

underline

Logical; if TRUE, text is underlined. Must be of length 1 or length(x).

strikeout

Logical; if TRUE, text has a strike through line. Must be of length 1 or length(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 ninecolors package.

fontsize

Font size in em units. Must be of length 1 or length(x). Can be NULL for 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

Run this code
# Basic styling
style_vector(c("Hello", "World"), bold = TRUE, color = "red")

# 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)
)

# Single style applied to all elements
style_vector(c("A", "B", "C"), color = "blue", fontsize = 1.2)

Run the code above in your browser using DataLab