--- title: "dftoHTML and dftoLaTeX: Data Frame Formatting" author: "Nick Huntington-Klein" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{dftoHTML and dftoLaTeX: Data Frame Formatting} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- The `vtable` package serves the purpose of outputting automatic variable documentation that can be easily viewed while continuing to work with data. `vtable` contains four main functions: `vtable()` (or `vt()`), `sumtable()` (or `st()`), `labeltable()`, and `dftoHTML()`/`dftoLaTeX()`. This vignette focuses on `dftoHTML()`/`dftoLaTeX()`. `dftoHTML()` and `dftoLaTeX` are helper functions used by `vtable()`, `sumtable()`, and `labeltable()`. They takes any data frame or matrix with column names and outputs HTML or LaTeX table code for that data. Note that none of the vignettes in this example are set to run because `dftoHTML` and `dftoLaTeX` output is intended to go to places other than Markdown (although both can certainly be used with 'asis' chunks to produce results in Markdown). ----- # The `dftoHTML()` function `dftoHTML()` syntax follows the following outline: ```{r, eval = FALSE} dftoHTML(data, out=NA, file=NA, note=NA, anchor=NA, col.width=NA, col.align=NA, row.names=FALSE, no.escape=NA) ``` `dftoHTML()` largely exists to serve `vtable()`, `sumtable()`, and `labeltable()`. What it does is takes a data set `data` and returns an HTML table with the contents of that data. Outside of its use with other `vtable` functions, `dftoHTML()` can also be used to keep a view of the data file open while working on the data, avoiding repeated calls to `head()` or similar, or switching back and forth between code tabs and data view tabs. ------ ## `data` `dftoHTML()` will accept any data set with a `colnames()` attribute. ```{r, eval = FALSE} library(vtable) data(LifeCycleSavings) dftoHTML(LifeCycleSavings) ``` ## out The `out` option determines what will be done with the resulting variable documentation file. There are several options for `out`: | Option | Result | |------------| -----------------------------------------| | browser | Loads HTML version of `data` in web browser. | | viewer | Loads HTML version of `data` in Viewer pane (RStudio only). | | htmlreturn | Returns HTML code for `data`. | By default, `vtable` will select 'viewer' if running in RStudio, and 'browser' otherwise. ```{r, eval=FALSE} library(vtable) data(LifeCycleSavings) dftoHTML(LifeCycleSavings) dftoHTML(LifeCycleSavings,out='browser') dftoHTML(LifeCycleSavings,out='viewer') htmlcode <- dftoHTML(LifeCycleSavings,out='htmlreturn') ``` ## `file` The `file` argument will write the HTML version of `data` to an HTML file and save it. Will automatically append 'html' filetype if the filename does not include a period. ```{r, eval=FALSE} data(LifeCycleSavings) dftoHTML(LifeCycleSavings,file='lifecycledata_htmlversion.html') ``` ## `note` `note` will add a table note in the last row. ```{r, eval = FALSE} dftoHTML(LifeCycleSavings,note='Data from Belsley, Kuh, and Welsch 1980'). ``` ## `anchor` `anchor` will add an anchor ID (`