The mutable package provides a flexible method for generating markup tables from the R programming language. It allows users to construct objects representing arbitrary tabular material and output the object into a variety of formats. LaTeX, HTML, and plain text output functions are included by default.
Users can supply their own formatting functions for these output types, and easily create their own. For example, the provided LaTeX output style for factors (percentage and fraction) can be completely changed if the user specifies their own muExportLatex function. The modular design of the package allows every markup decision to be overridden easily and consistently. The result is that the user is in complete control over the final markup produced, and that multiple versions of the same table can easily be produced from the same data simultaneously.
require(devtools) require(Hmisc) install_github("mutable", "erikriverson")
Load sample data
Give unlabeled variables appropriate labels
label(airquality$Ozone) <- 'Ozone (ppb)' label(airquality$Solar.R) <- 'Solar R (lang)' label(airquality$Wind) <- 'Wind (mph)' label(airquality$Temp) <- 'Temperature (degrees F)' airquality$Month <- factor(airquality$Month, labels = month.abb[5:9])
Use the mutable formula interface to create a complete table, by default in plain text, LaTeX, and HTML formats
library(mutable) m1 <- mutable(Month ~ Ozone + Solar.R + Wind + Temp, data = airquality)
Print the table in the running R session
Print out HTML and LaTeX version of the table using default export functions. Note all rows/columns/cells are uniquely identified for CSS customization.
The table contains the following information.
|Solar R (lang)||146||181.3/115.08||190.17/92.88||216.48/80.57||171.86/76.83||167.43/79.12||185.93/90.06|
|Temperature (degrees F)||153||65.55/6.85||79.1/6.6||83.9/4.32||83.97/6.59||76.9/8.36||77.88/9.47|