Summarizes a column from literature review data and returns a formatted
gt::gt() table showing each category, its associated study IDs,
frequency, and percentage.
Usage
reviewTable(
data,
col,
sep = "\r\n",
study_id = StudyID,
latex = FALSE,
cite = FALSE,
na.rm = TRUE,
na_label = "Not reported",
na_in_percent = TRUE,
na_last = FALSE
)Arguments
- data
A data frame with at least a study ID column and the column named by
col.- col
Column to summarize (quoted or unquoted).
- sep
Character. Separator for multi-value cells. Defaults to
"\r\n".- study_id
Column containing study identifiers (quoted or unquoted). Defaults to
StudyID.- latex
Logical. If
TRUE, returns the table as LaTeX code viagt::as_latex()instead of agt::gt()object. Defaults toFALSE.- cite
Logical. If
TRUE, treats values instudy_idas BibTeX reference keys and wraps the per-row study list in\\cite{...}. Defaults toFALSE.- na.rm
Logical. Drop missing values? Defaults to
TRUE.- na_label
Character. Label for missing values when
na.rm = FALSE. Defaults to"Not reported".- na_in_percent
Logical. Include missing rows in the percentage denominator? Defaults to
TRUE.- na_last
Logical. If
TRUE, place the missing-value category last regardless of its frequency. Defaults toFALSE.
Value
A gt::gt() table, or a LaTeX character string if latex = TRUE.
The LaTeX output prints cleanly in the console, and renders automatically
in knitr/R Markdown chunks with results = "asis".
Examples
df <- data.frame(
StudyID = c("S1", "S2", "S3", "S4"),
Design = c("RCT", "Cohort", "RCT", "Case-control"),
stringsAsFactors = FALSE
)
reviewTable(df, Design)
Design
Studies
Frequency
Percent
reviewTable(df, Design, latex = TRUE, cite = TRUE)
#> \begin{table}[t]
#> \fontsize{12.0pt}{14.0pt}\selectfont
#> \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}llrr}
#> \toprule
#> Design & Studies & Frequency & Percent \\
#> \midrule\addlinespace[2.5pt]
#> RCT & \cite{S1,S3} & 2 & 50\% \\
#> Cohort & \cite{S2} & 1 & 25\% \\
#> Case-control & \cite{S4} & 1 & 25\% \\
#> \bottomrule
#> \end{tabular*}
#> \end{table}
#>
