knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

Build Status Build status

tidytableR

The goal of tidytableR is to is to reshape data from a tidy format into one that is suitable for presentation. Specifically, it works best when used to make complex, publication-quality tables from output created by dplyr::summarise or tidyr::gather. It allows users to map column names from an input data frame to elements of an output table.

The package was developed from code meant to act as a wrapper script for the htmlTable function in the htmlTable package. In fact, its first release was as the tidyHtmlTable function within the htmlTable package. Therefore, many of the variable names and symantics used within are related to those used in the htmlTable package.

Installation

You can install tidytableR from github with:

# install.packages("devtools")
devtools::install_github("graggsd/tidytableR")

Examples

library(tidytableR)
library(magrittr)
library(dplyr)
library(tidyr)
library(tibble)

Prep Data

Turn mtcars data into a tidy dataset.

td <- mtcars %>%
    rownames_to_column %>%
    select(rowname, cyl, gear, hp, mpg, qsec) %>%
    gather(per_metric, value, hp, mpg, qsec)

Compute 4 summary statistics for each of the 3 performance metrics, grouped number of cylinders and gears.

tidy_summary <- td %>%
    group_by(cyl, gear, per_metric) %>% 
    summarise(Mean = round(mean(value), 1),
              SD = round(sd(value), 1),
              Min = round(min(value), 1),
              Max = round(max(value), 1)) %>%
    gather(summary_stat, value, Mean, SD, Min, Max) %>% 
    ungroup %>% 
    mutate(gear = paste(gear, "Gears"),
           cyl = paste(cyl, "Cylinders"))

Output html table

Example 1

tidy_summary  %>% 
    tidy_htmlTable(header = "gear",
                   cgroup1 = "cyl",
                   cell_value = "value", 
                   rnames = "summary_stat",
                   rgroup = "per_metric")

Example 2

tidy_summary  %>% 
    tidy_htmlTable(header = "summary_stat",
                   cgroup1 = "per_metric",
                   cell_value = "value", 
                   rnames = "gear",
                   rgroup = "cyl")


graggsd/tidytableR documentation built on May 16, 2019, 11:07 a.m.