Summarize data sets and create publication-quality tables for inclusion in 'tex' documents.
Creating general tables
To create a table with a single function call, use
stable()for single page tables andstable_long()for longtableAlternatively, use
st_new()to create a s-table object and pipe to other st-functions; see the documentation links instable()to discover these functions; finally, create an stable object withst_make()
Table data grooming and sanitization
The functions
tab_prime()andtriage_data()are called to get the data frame ready to be in tabular format (seemake_tabular()The function
tab_escape()is used to escape%and_in the table (sanitization); useoptions(pmtables.escape = ...)to change the set of escape characters or set that option toNULLto prevent any sanitizationAny unit of data that has a character escaped with double backslash (
\\) or that contains a math expression with two$will not be sanitizedThe function
tab_escape()also performs the following substitutions:change
~to$\\sim$change
>to$>$change
<to$<$
Summarizing and creating tables
Use
pt_cont_wide()to create continuous data summary in wide formatUse
pt_cont_long()to create continuous data summary in long formatUse
pt_cat_wide()to create discrete data summaries in wide formatUse
pt_cat_long()to create discrete data summaries in long formatUse
pt_data_inventory()to create a table summarizing observations and individuals in a data setAll of the above functions return an object with class
pmtable, which is a list; you can access the summarized data by looking at thedataslot; otherwise, pass thepmtableobject tostable()oras_stable()in order to create the table. See class-pmtable for details around this objectYou can configure the digits in these summaries with
new_digits()
Helper functions for working with data frames
Make text bold with
tex_bold()or italics withtex_it()Clear repeated values in a column with
clear_grouped_values()andtab_clear_reps()Use
tab_edit()to do find / replace on your data frameUse
df_grep_rows()anddf_grepl_rows()to find rows that match a given patternUse
sig()ordigit1()to control the number of digits that are displayed; both these functions return character
Functions to align columns
When you want latex to figure out column widths:
cols_left(),cols_right(),cols_center(),cols_align()When you want to fix the width of a specific column in the table:
col_ragged(),col_fixed()
Functions to modify or configure a table
Alter column names:
tab_cols()Partition a table into panels:
as.panel()androwpanel()Create groups of columns with column spanners:
colgroup()andcolsplit()Configure row spacing, column spacing, or font size:
tab_size()Configure the appearance of table notes:
noteconf()Identify rows that are "summary" rows:
sumrow(); these rows can get automatically styled with a label (optionally in bold font) and a horizontal line above
Preview tables
Use
st2viewer()to send s-table output totexPreview::tex_preview()Use
st2article()orst2report()to render several tables in a stand-alone tex document rendered directly bypdflatex(no involvement ofRmarkdownorpandoc); this requirespdflatexto be installed and in yourPATH.Use
st2doc()to render a pdf file with one or more tables using pandoc; in general, usest2article()insteadPipe tables to
st_asis()to render a table in line while knitting an Rmd documentUse
st_wrap()to wrap s-table output in atableenvironment and optionally send the output tostdout(); this is helpful when rendering tables in Rmarkdown documents. There is anst_wrap()method for longtables that won't add the table environment.Use
as_lscape()to markstable()orstable_long()output for display in landscape environment
Save s-tables
Use
stable_save()to write anstableorstable_longobject to fileNote that there is a
dirargument to that function that lets you route the table to a specific directory;dirdefaults to thepmtables.diroption, so settingoptions(pmtables.dir = "../deliv/table")will route the table to that directory without requiring additional input
Latex / markdown information
The following latex packages are required in your Rmd or latex document:
threeparttablearraybooktabspdflscapelongtable(only when long tables are in the document)float(mainly if you want to useHplacement in your Rmd output)
In Rmd, include these as extra_dependencies. Or try using
st_use_knit_deps() to include these packages via knitr::knit_meta_add();
this is only when you are including a table in a knit Rmd document.
You may also want to include this package:
mathdesignwith optionutopia
The tables are generated with defaults that look sensible when the table is
rendered with single spacing. If you are working in a 1.5 spaced
environment, the table may look roomy. In that case, load the setspace
package and switch to singlespacing prior to sourcing the table.
If you render tables in an Rmarkdown document with processing by pandoc,
pandoc may make mistakes when parsing the latex code. To keep pandoc
from making parsing errors, use latex code fence. This formatting can
be added to your table with the st_latex() command. You can see what the
fence looks like by running st_latex("abc"). Asserting that the code is
latex can also be accomplished with pt_wrap() and using the
context = "rmd" option. See st2article() for instructions on
how to view a complete working latex example.
Glossaries
Use
read_glossary()to read abbreviations and definitions from a file in.texor.yamlformat.Use
as_glossary()to create a glossary object in R.Use
select_glossary()to select specific labels from a glossary object.Use
glossary_notes()to create table notes from a glossary object.Use
st_notes_glo()to create glossary notes from a glossary object and attach to a table in a pipeline.
Data sets
Author
Maintainer: Kyle Baron kyleb@metrumrg.com
Other contributors:
Anna-Christina Nevison annan@metrumrg.com [contributor]
Katherine Kay katherinek@metrumrg.com [contributor]
Devin Pastoor devin.pastoor@gmail.com [contributor]
Kyle Barrett barrettk@metrumrg.com [contributor]
