knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

htable

The goal of htable is to easily and transparently translate R data.frames into styled HTML tables.

Installation

Make sure to build with vignettes to view examples of styling the tables.

# install.packages("devtools")
devtools::install_github("fazetu/htable", build_vignettes = TRUE)

Examples

library(htable)
ex <- data.frame(
  A = 1:10,
  B = 10:1,
  C = -4:5,
  D = letters[1:10],
  E = c(1, NA, 2, NA, 3, NA, 4, NA, 5, NA),
  Pct = runif(10),
  Big = 100000:100009,
  Money = c(100, 200, -100, -200, 1000.11, 2000.22, -1000.11, -2000.22, 0, 0.11),
  stringsAsFactors = FALSE
)

First create the HTable object in one of two ways:

# ht <- HTable$new(ex)
ht <- htable(ex)

To get the HTML for this table:

ht$render()

To write the HTML to a file:

ht$writeLines("table.html")

In an RMarkdown document, include in your chunk settings results="asis" in order to get the actual HTML table to render. This chunk has results="asis".

ht$Rmd()

When not working in an RMarkdown file, use the View() method to see the rendered HTML table.

ht$View()

For examples on how to style the tables, see the vignette.

vignette("htable", package = "htable")


fazetu/htable documentation built on Feb. 12, 2020, 10:13 a.m.