Function that will return tables used in reports.

Usage

mst(
tab,
col_names = colnames(tab),
type = "pdf",
cap = "",
label = knitr::opts_currentget("label"), digs = 0, align = NULL, fs = 8, lsd = FALSE ) Arguments tab Data frame or matrix representing the table. col_names Character vector with column names. Defaults colnames(tab). type Character string defining output, either "html" or "pdf". Default is "pdf". cap Character string with table caption. Empty string by default. label Character string defining the label in case the table needs to be referenced elsewhere in the overall document. For instance, setting this to 'my_table' the corresponding inline rmarkdown reference to use is \@ref(tab:my_table). Please note that for this to work for both LaTex and HTML the bookdown document processing functions must be used, i.e. bookdown::pdf_document2() and bookdown::html_document2(), respectively. Default value is knitr::opts_currentget("label") in which case the name of the current R chunk will be used as label.

digs

Integer number of digits to use. 0 by default.

align

Character vector specifying column alignment in the LaTeX way, e.g. c("l", "c", "r") will align the first column to the left, center the second and right-align the last one. Default is NULL in which case numeric columns are right-aligned and all other columns are left-aligned.

fs

Integer providing the font size. Applies only for pdf output. Default value is 8.

lsd

Logical if table is to be scaled down. Applies only for pdf output. FALSE by default.

Value

Character string containing RMarkdown table code

Details

mst() creates RMarkdown code for creating standard tables.

Examples

mst(tab = mtcars[1:10, ])
#> \begin{table}[H]
#>
#> \caption{}
#> \centering
#> \fontsize{8}{10}\selectfont
#> \begin{tabular}[t]{lrrrrrrrrrrr}
#> \toprule
#>   & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb\\
#> \midrule
#> Mazda RX4 & 21 & 6 & 160 & 110 & 4 & 3 & 16 & 0 & 1 & 4 & 4\\
#> Mazda RX4 Wag & 21 & 6 & 160 & 110 & 4 & 3 & 17 & 0 & 1 & 4 & 4\\
#> Datsun 710 & 23 & 4 & 108 & 93 & 4 & 2 & 19 & 1 & 1 & 4 & 1\\
#> Hornet 4 Drive & 21 & 6 & 258 & 110 & 3 & 3 & 19 & 1 & 0 & 3 & 1\\
#> Hornet Sportabout & 19 & 8 & 360 & 175 & 3 & 3 & 17 & 0 & 0 & 3 & 2\\