dualTable: Output HTML and LaTeX Tables

dualTableR Documentation

Output HTML and LaTeX Tables

Description

This is a function for outputting a more advanced table than what xtable, ztable, or kable() allows. It's aim is to provide the combined functionality of the the Hmisc latex() and htmlTable htmlTable. See documentation of those functions for more details.

Usage

dualTable(
    my_tbl,
    where="H",
    align=paste(rep('c', ncol(my_tbl)), collapse=''),
    caption="",
    css.class="gmisc_table breakboth",
    use.xtable=FALSE,
    files="",
    ...)

Arguments

my_tbl

The matrix/data.frame with the data.

where

Passed to latex. Specifies placement of floats if a table environment is used. Default is "H", which places the table in the exact location it appears in the document. To allow tables to appear in the middle of a page of text you might specify where="!htbp" to latex.default.

align

A character strings specifying column alignments, defaulting to paste(rep('c',ncol(my_tbl)),collapse='') to center. Valid alignments are l = left, c = center and r = right. You can also specify align='c|c' and other LaTeX tabular formatting. If you want to set the alignment of the rownames this string needst to be ‘ncol(x) + 1’, otherwise it automatically pads the string with a left alignment for the rownames.

caption

Adds a table caption.

css.class

The html CSS class for the table. This allows directing html formatting through CSS directly at all instances of that class. Default includes breakboth class. This inserts a page break before and after the table, which prevents tables from being broken up between pages when printed from HTML or rendered as an EPUB document.

use.xtable

Boolean argument (defaults to FALSE) indicating whether xtable is used.

files

Path to output file(s) to save text to. Default is ‘""’, which is prints to the standard output connection (typically the rendered .md file). Multiple files, or file(s) and stdout, are supported.

...

Passed onto htmlTable and/or latex.

Value

string Returns a character string containing the text for both the table to be rendered in HTML or PDF via LaTeX. String also contains HTML/Markdown comments to demarcate the location of the each code type, which is used later for post-processing markdown text files using renderMultiDocument.

Examples

# A simple output
options(table_number=0)

output <- matrix(1:4,
                 ncol=2,
                 dimnames = list(list("Row 1", "Row 2"),
                                 list("Column 1", "Column 2")))

dualTable(output, caption="Simple Test Table")

# An advanced output
## Not run: 
output <-
  matrix(ncol=6, nrow=8)

for (nr in 1:nrow(output)){
  for (nc in 1:ncol(output)){
    output[nr, nc] <-
      paste0(nr, ":", nc)
  }
}

dualTable(output, align=paste(rep('r', ncol(output)), collapse=''),
          header =  paste(c("1st", "2nd",
                            "3rd", "4th",
                            "5th", "6th"),
                          "hdr"),
          rnames = paste(c("1st", "2nd",
                           "3rd",
                           paste0(4:8, "th")),
                         "row"),
          rgroup = paste("Group", LETTERS[1:3]),
          n.rgroup = c(2,4,nrow(output) - 6),
          cgroup = c("", "Cgroup 1", "Cgroup 2&dagger;"),
          n.cgroup = c(2,2,2),
          caption="Basic table with both column spanners (groups) and row groups",
          tfoot="&dagger; A table footer commment",
          cspan.rgroup = 2,
          col.columns = c(rep("none", 2),
                          rep("#F5FBFF", 4)),
          col.rgroup = c("none", "#F7F7F7"),
          css.cell = "padding-left: .5em; padding-right: .2em;")
  
## End(Not run)

CenterForAssessment/Literasee documentation built on July 2, 2023, 6:21 p.m.