html_align: Align html

View source: R/utils2.R

html_alignR Documentation

Align html

Description

Align text in columns of an htmlTable at a specific location (similar to align or eqnarray environments in latex).

Usage

html_align(x, sep = " ", where = "&&", min_width = "35px")

Arguments

x

an object of class htmlTable

sep

a character string used as the center of alignment

where

a character string or regular expression (see examples) defining where strings should be aligned; the easiest method is to use "&&" at the desired alignment point

min_width

minimum width of the span tag; too narrow will not align strings but too wide adds whitespace

Examples

tmp <- within(cars, {
  align2 <- sprintf('%s&&(%s)', speed, dist)
  align1 <- sprintf('%s (%s)', speed, dist)
  raw    <- sprintf('%s - (%s)', speed, dist)
})

ht <- htmlTable::htmlTable(
  head(tmp), n.cgroup = 2:3, cgroup = c('raw', 'align'),
  caption = 'caption', rnames = FALSE
)

## default
structure(ht, class = 'htmlTable')

## align at '&&'
structure(html_align(ht), class = 'htmlTable')
structure(html_align(ht, ' --- '), class = 'htmlTable')

## align at '&&' or ' '
## the regex should capture the left text in group 1, use non-capture
## for separating text, andn capture the right text in group 2
structure(
  html_align(ht, '&nbsp;', '(\\d+)(?: |&&)([()0-9]+)'),
  class = 'htmlTable'
)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.