Last data update: 2014.03.03

R: Generate a table header or footer from column names
tableHeaderR Documentation

Generate a table header or footer from column names

Description

Convenience functions to generate a table header (<thead></thead>) or footer (<tfoot></tfoot>) given the column names. They are basically wrappers of htmltools::tags$th applied to the column names.

Usage

tableHeader(names, escape = TRUE)

tableFooter(names, escape = TRUE)

Arguments

names

a character vector of the column names of the table (if it is an object with column names, its column names will be used instead)

escape

whether to escape the names (see datatable)

Value

A tag object generated by htmltools::tags.

Examples

library(DT)
tableHeader(iris)  # or equivalently,
tableHeader(colnames(iris))
tableFooter(iris)  # footer

library(htmltools)
tags$table(tableHeader(iris), tableFooter(iris))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DT)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DT/tableHeader.Rd_%03d_medium.png", width=480, height=480)
> ### Name: tableHeader
> ### Title: Generate a table header or footer from column names
> ### Aliases: tableFooter tableHeader
> 
> ### ** Examples
> 
> library(DT)
> tableHeader(iris)  # or equivalently,
<thead>
  <tr>
    <th>Sepal.Length</th>
    <th>Sepal.Width</th>
    <th>Petal.Length</th>
    <th>Petal.Width</th>
    <th>Species</th>
  </tr>
</thead>
> tableHeader(colnames(iris))
<thead>
  <tr>
    <th>Sepal.Length</th>
    <th>Sepal.Width</th>
    <th>Petal.Length</th>
    <th>Petal.Width</th>
    <th>Species</th>
  </tr>
</thead>
> tableFooter(iris)  # footer
<tfoot>
  <tr>
    <th>Sepal.Length</th>
    <th>Sepal.Width</th>
    <th>Petal.Length</th>
    <th>Petal.Width</th>
    <th>Species</th>
  </tr>
</tfoot>
> 
> library(htmltools)
> tags$table(tableHeader(iris), tableFooter(iris))
<table>
  <thead>
    <tr>
      <th>Sepal.Length</th>
      <th>Sepal.Width</th>
      <th>Petal.Length</th>
      <th>Petal.Width</th>
      <th>Species</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <th>Sepal.Length</th>
      <th>Sepal.Width</th>
      <th>Petal.Length</th>
      <th>Petal.Width</th>
      <th>Species</th>
    </tr>
  </tfoot>
</table>
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>