diff --git a/DESCRIPTION b/DESCRIPTION index 2d8abe0..8bc4ccb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Imports: survey, survival, xtable -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.1 Suggests: rmarkdown VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 657fc32..ce40725 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(formatp) +export(hide_rows) export(tabcoxph) export(tabfreq) export(tabfreq.svy) diff --git a/R/hide_rows.R b/R/hide_rows.R new file mode 100644 index 0000000..617ee72 --- /dev/null +++ b/R/hide_rows.R @@ -0,0 +1,24 @@ +#' Hide rows of selected levels of dichotomous variables from a Table +#' (e.g. "no" category of Smoking) +#' +#' @param tab Data frame. +#' @param rows Character string with name of levels (rows) which should be hidden. +#' +#' @return Data frame which you can print in R (e.g. with \strong{xtable}'s +#' \code{\link[xtable]{xtable}} or \strong{knitr}'s \code{\link[knitr]{kable}}). +#' +#' @examples +#' # Compare age, sex, and race by treatment group +#' # Hide level "Male" of Variable "sex" +#' tabmulti(Age + Sex + Race ~ Group, data = tabdata) %>% hide_rows(rows = c("male")) %>% kable() +#' +#' +#' @export +hide_rows <- function(tab, rows, ...){ + + rows <- paste("\\ \\ \\ ", tolower(rows), sep = "") + tab <- tab[which(!tolower(tab$Variable) %in% rows),] + + return(tab) + +} diff --git a/R/tabfreq_svy.R b/R/tabfreq_svy.R index 743404f..73b9a2d 100644 --- a/R/tabfreq_svy.R +++ b/R/tabfreq_svy.R @@ -224,7 +224,7 @@ tabfreq.svy <- function(formula, } else if (cell == "N") { part1 <- rowsums.svycounts } else if (cell == "col.percent") { - part1 <- percents + part1 <- paste(sprintf(spf, percents), sep = "") } if (parenth == "none") { part2 <- NULL @@ -233,9 +233,9 @@ tabfreq.svy <- function(formula, } else if (parenth == "N") { part2 <- rowsums.svycounts } else if (parenth == "col.percent") { - part2 <- percents + part2 <- paste(" (", sprintf(spf, percents), ")", sep = "") #percents } else if (parenth == "se") { - part2 <- ses + part2 <- paste("(", sprintf(spf, ses), ")", sep = "") } else if (parenth == "ci") { zcrit <- qnorm(p = 0.975) lower <- percents - zcrit * ses diff --git a/man/formatp.Rd b/man/formatp.Rd index d3e7510..c161a2c 100644 --- a/man/formatp.Rd +++ b/man/formatp.Rd @@ -4,8 +4,14 @@ \alias{formatp} \title{Format P-values for Functions in the \pkg{tab} Package} \usage{ -formatp(p, decimals = c(2, 3), cuts = 0.01, lowerbound = 0.001, - leading0 = TRUE, avoid1 = FALSE) +formatp( + p, + decimals = c(2, 3), + cuts = 0.01, + lowerbound = 0.001, + leading0 = TRUE, + avoid1 = FALSE +) } \arguments{ \item{p}{Numeric vector of p-values.} diff --git a/man/hide_rows.Rd b/man/hide_rows.Rd new file mode 100644 index 0000000..3f1dc37 --- /dev/null +++ b/man/hide_rows.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hide_rows.R +\name{hide_rows} +\alias{hide_rows} +\title{Hide rows of selected levels of dichotomous variables from a Table +(e.g. "no" category of Smoking)} +\usage{ +hide_rows(tab, rows, ...) +} +\arguments{ +\item{tab}{Data frame.} + +\item{rows}{Character string with name of levels (rows) which should be hidden.} +} +\value{ +Data frame which you can print in R (e.g. with \strong{xtable}'s +\code{\link[xtable]{xtable}} or \strong{knitr}'s \code{\link[knitr]{kable}}). +} +\description{ +Hide rows of selected levels of dichotomous variables from a Table +(e.g. "no" category of Smoking) +} +\examples{ +# Compare age, sex, and race by treatment group +# Hide level "Male" of Variable "sex" +tabmulti(Age + Sex + Race ~ Group, data = tabdata) \%>\% hide_rows(rows = c("male")) \%>\% kable() + + +} diff --git a/man/tab.Rd b/man/tab.Rd index c905bd5..d81ff67 100644 --- a/man/tab.Rd +++ b/man/tab.Rd @@ -3,7 +3,6 @@ \docType{package} \name{tab} \alias{tab} -\alias{tab-package} \title{Create Summary Tables for Statistical Reports} \description{ Contains functions for creating various types of summary tables, e.g. diff --git a/man/tabcoxph.Rd b/man/tabcoxph.Rd index a525215..e619415 100644 --- a/man/tabcoxph.Rd +++ b/man/tabcoxph.Rd @@ -4,10 +4,19 @@ \alias{tabcoxph} \title{Create Summary Table for Fitted Cox Proportional Hazards Model} \usage{ -tabcoxph(fit, columns = c("beta.se", "hr.ci", "p"), var.labels = NULL, - factor.compression = 1, sep.char = ", ", indent.spaces = 3, - latex = TRUE, decimals = 2, formatp.list = NULL, - print.html = FALSE, html.filename = "table1.html") +tabcoxph( + fit, + columns = c("beta.se", "hr.ci", "p"), + var.labels = NULL, + factor.compression = 1, + sep.char = ", ", + indent.spaces = 3, + latex = TRUE, + decimals = 2, + formatp.list = NULL, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{fit}{Fitted \code{\link[survival]{coxph}} object.} diff --git a/man/tabfreq.Rd b/man/tabfreq.Rd index c99c591..987f5b3 100644 --- a/man/tabfreq.Rd +++ b/man/tabfreq.Rd @@ -4,15 +4,32 @@ \alias{tabfreq} \title{Create Frequency Table} \usage{ -tabfreq(formula = NULL, data = NULL, x = NULL, y = NULL, - columns = c("xgroups", "p"), cell = "counts", - parenth = "col.percent", sep.char = ", ", test = "chi.fisher", - xlevels = NULL, yname = NULL, ylevels = NULL, - compress.binary = FALSE, yname.row = TRUE, indent.spaces = 3, - text.label = NULL, quantiles = NULL, quantile.vals = FALSE, - latex = TRUE, decimals = 1, formatp.list = NULL, - n.headings = FALSE, print.html = FALSE, - html.filename = "table1.html") +tabfreq( + formula = NULL, + data = NULL, + x = NULL, + y = NULL, + columns = c("xgroups", "p"), + cell = "counts", + parenth = "col.percent", + sep.char = ", ", + test = "chi.fisher", + xlevels = NULL, + yname = NULL, + ylevels = NULL, + compress.binary = FALSE, + yname.row = TRUE, + indent.spaces = 3, + text.label = NULL, + quantiles = NULL, + quantile.vals = FALSE, + latex = TRUE, + decimals = 1, + formatp.list = NULL, + n.headings = FALSE, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{formula}{Formula, e.g. \code{Sex ~ Group}.} diff --git a/man/tabfreq.svy.Rd b/man/tabfreq.svy.Rd index 9f0fd7f..9b44d9d 100644 --- a/man/tabfreq.svy.Rd +++ b/man/tabfreq.svy.Rd @@ -4,14 +4,29 @@ \alias{tabfreq.svy} \title{Create Frequency Table (for Complex Survey Data)} \usage{ -tabfreq.svy(formula, design, columns = c("xgroups", "p"), - cell = "col.percent", parenth = "se", sep.char = ", ", - xlevels = NULL, yname = NULL, ylevels = NULL, - compress.binary = FALSE, yname.row = TRUE, indent.spaces = 3, - text.label = NULL, latex = TRUE, decimals = 1, - svychisq.list = NULL, formatp.list = NULL, n.headings = FALSE, - N.headings = FALSE, print.html = FALSE, - html.filename = "table1.html") +tabfreq.svy( + formula, + design, + columns = c("xgroups", "p"), + cell = "col.percent", + parenth = "se", + sep.char = ", ", + xlevels = NULL, + yname = NULL, + ylevels = NULL, + compress.binary = FALSE, + yname.row = TRUE, + indent.spaces = 3, + text.label = NULL, + latex = TRUE, + decimals = 1, + svychisq.list = NULL, + formatp.list = NULL, + n.headings = FALSE, + N.headings = FALSE, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{formula}{Formula, e.g. \code{Race ~ Sex}.} diff --git a/man/tabgee.Rd b/man/tabgee.Rd index ece6f03..79d70c8 100644 --- a/man/tabgee.Rd +++ b/man/tabgee.Rd @@ -4,11 +4,21 @@ \alias{tabgee} \title{Create Summary Table for Fitted Generalized Estimating Equation Model} \usage{ -tabgee(fit, data = NULL, columns = NULL, robust = TRUE, - var.labels = NULL, factor.compression = 1, sep.char = ", ", - indent.spaces = 3, latex = TRUE, decimals = 2, - formatp.list = NULL, print.html = FALSE, - html.filename = "table1.html") +tabgee( + fit, + data = NULL, + columns = NULL, + robust = TRUE, + var.labels = NULL, + factor.compression = 1, + sep.char = ", ", + indent.spaces = 3, + latex = TRUE, + decimals = 2, + formatp.list = NULL, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{fit}{Fitted \code{\link[gee]{gee}} object.} diff --git a/man/tabglm.Rd b/man/tabglm.Rd index be49696..90be493 100644 --- a/man/tabglm.Rd +++ b/man/tabglm.Rd @@ -4,10 +4,19 @@ \alias{tabglm} \title{Create Summary Table for Fitted Generalized Linear Model} \usage{ -tabglm(fit, columns = NULL, xvarlabels = NULL, - factor.compression = 1, sep.char = ", ", indent.spaces = 3, - latex = TRUE, decimals = 2, formatp.list = NULL, - print.html = FALSE, html.filename = "table1.html") +tabglm( + fit, + columns = NULL, + xvarlabels = NULL, + factor.compression = 1, + sep.char = ", ", + indent.spaces = 3, + latex = TRUE, + decimals = 2, + formatp.list = NULL, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{fit}{Fitted \code{\link[stats]{glm}} object.} diff --git a/man/tabmeans.Rd b/man/tabmeans.Rd index ed62ff1..6f4f8ed 100644 --- a/man/tabmeans.Rd +++ b/man/tabmeans.Rd @@ -4,12 +4,26 @@ \alias{tabmeans} \title{Create Table Comparing Group Means} \usage{ -tabmeans(formula = NULL, data = NULL, x = NULL, y = NULL, - columns = c("xgroups", "p"), parenth = "sd", sep.char = ", ", - variance = "unequal", xlevels = NULL, yname = NULL, - text.label = NULL, quantiles = NULL, quantile.vals = FALSE, - decimals = NULL, formatp.list = NULL, n.headings = TRUE, - print.html = FALSE, html.filename = "table1.html") +tabmeans( + formula = NULL, + data = NULL, + x = NULL, + y = NULL, + columns = c("xgroups", "p"), + parenth = "sd", + sep.char = ", ", + variance = "unequal", + xlevels = NULL, + yname = NULL, + text.label = NULL, + quantiles = NULL, + quantile.vals = FALSE, + decimals = NULL, + formatp.list = NULL, + n.headings = TRUE, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{formula}{Formula, e.g. \code{BMI ~ Group}.} diff --git a/man/tabmeans.svy.Rd b/man/tabmeans.svy.Rd index d56456f..fdfdccc 100644 --- a/man/tabmeans.svy.Rd +++ b/man/tabmeans.svy.Rd @@ -4,11 +4,23 @@ \alias{tabmeans.svy} \title{Create Table Comparing Group Means (for Complex Survey Data)} \usage{ -tabmeans.svy(formula, design, columns = c("xgroups", "p"), - parenth = "sd", sep.char = ", ", xlevels = NULL, yname = NULL, - text.label = NULL, decimals = 1, anova.svyglm.list = NULL, - formatp.list = NULL, n.headings = FALSE, N.headings = FALSE, - print.html = FALSE, html.filename = "table1.html") +tabmeans.svy( + formula, + design, + columns = c("xgroups", "p"), + parenth = "sd", + sep.char = ", ", + xlevels = NULL, + yname = NULL, + text.label = NULL, + decimals = 1, + anova.svyglm.list = NULL, + formatp.list = NULL, + n.headings = FALSE, + N.headings = FALSE, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{formula}{Formula, e.g. \code{BMI ~ Sex}.} diff --git a/man/tabmedians.Rd b/man/tabmedians.Rd index 6fbd591..725ba05 100644 --- a/man/tabmedians.Rd +++ b/man/tabmedians.Rd @@ -4,12 +4,25 @@ \alias{tabmedians} \title{Create Table Comparing Group Medians} \usage{ -tabmedians(formula = NULL, data = NULL, x = NULL, y = NULL, - columns = c("xgroups", "p"), parenth = "iqr", sep.char = ", ", - xlevels = NULL, yname = NULL, text.label = NULL, - quantiles = NULL, quantile.vals = FALSE, decimals = NULL, - formatp.list = NULL, n.headings = TRUE, print.html = FALSE, - html.filename = "table1.html") +tabmedians( + formula = NULL, + data = NULL, + x = NULL, + y = NULL, + columns = c("xgroups", "p"), + parenth = "iqr", + sep.char = ", ", + xlevels = NULL, + yname = NULL, + text.label = NULL, + quantiles = NULL, + quantile.vals = FALSE, + decimals = NULL, + formatp.list = NULL, + n.headings = TRUE, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{formula}{Formula, e.g. \code{BMI ~ Group}.} diff --git a/man/tabmedians.svy.Rd b/man/tabmedians.svy.Rd index 56c6d48..0a323df 100644 --- a/man/tabmedians.svy.Rd +++ b/man/tabmedians.svy.Rd @@ -4,11 +4,23 @@ \alias{tabmedians.svy} \title{Create Table Comparing Group Medians (for Complex Survey Data)} \usage{ -tabmedians.svy(formula, design, columns = c("xgroups", "p"), - parenth = "iqr", sep.char = ", ", xlevels = NULL, yname = NULL, - text.label = NULL, decimals = NULL, svyranktest.list = NULL, - formatp.list = NULL, n.headings = FALSE, N.headings = FALSE, - print.html = FALSE, html.filename = "table1.html") +tabmedians.svy( + formula, + design, + columns = c("xgroups", "p"), + parenth = "iqr", + sep.char = ", ", + xlevels = NULL, + yname = NULL, + text.label = NULL, + decimals = NULL, + svyranktest.list = NULL, + formatp.list = NULL, + n.headings = FALSE, + N.headings = FALSE, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{formula}{Formula, e.g. \code{BMI ~ Sex}.} diff --git a/man/tabmulti.Rd b/man/tabmulti.Rd index 7fbb65a..3d8ed14 100644 --- a/man/tabmulti.Rd +++ b/man/tabmulti.Rd @@ -5,14 +5,31 @@ \title{Create Table Comparing Characteristics Across Levels of a Categorical Variable} \usage{ -tabmulti(formula = NULL, data, xvarname = NULL, yvarnames = NULL, - ymeasures = NULL, columns = c("xgroups", "p"), - listwise.deletion = FALSE, sep.char = ", ", xlevels = NULL, - yvarlabels = NULL, ylevels = NULL, indent.spaces = 3, - quantiles = NULL, quantile.vals = FALSE, latex = TRUE, - decimals = NULL, formatp.list = NULL, n.headings = FALSE, - print.html = FALSE, html.filename = "table1.html", - tabmeans.list = NULL, tabmedians.list = NULL, tabfreq.list = NULL) +tabmulti( + formula = NULL, + data, + xvarname = NULL, + yvarnames = NULL, + ymeasures = NULL, + columns = c("xgroups", "p"), + listwise.deletion = FALSE, + sep.char = ", ", + xlevels = NULL, + yvarlabels = NULL, + ylevels = NULL, + indent.spaces = 3, + quantiles = NULL, + quantile.vals = FALSE, + latex = TRUE, + decimals = NULL, + formatp.list = NULL, + n.headings = FALSE, + print.html = FALSE, + html.filename = "table1.html", + tabmeans.list = NULL, + tabmedians.list = NULL, + tabfreq.list = NULL +) } \arguments{ \item{formula}{Formula, e.g. \code{Age + Sex + Race + BMI ~ Group}.} diff --git a/man/tabmulti.svy.Rd b/man/tabmulti.svy.Rd index 6357882..2b496ff 100644 --- a/man/tabmulti.svy.Rd +++ b/man/tabmulti.svy.Rd @@ -5,14 +5,30 @@ \title{Create Table Comparing Characteristics Across Levels of a Categorical Variable (for Complex Survey Data)} \usage{ -tabmulti.svy(formula = NULL, design, xvarname = NULL, - yvarnames = NULL, ymeasures = NULL, columns = c("xgroups", "p"), - listwise.deletion = FALSE, sep.char = ", ", xlevels = NULL, - yvarlabels = NULL, ylevels = NULL, indent.spaces = 3, - latex = TRUE, decimals = NULL, formatp.list = NULL, - n.headings = FALSE, N.headings = FALSE, print.html = FALSE, - html.filename = "table1.html", tabmeans.svy.list = NULL, - tabmedians.svy.list = NULL, tabfreq.svy.list = NULL) +tabmulti.svy( + formula = NULL, + design, + xvarname = NULL, + yvarnames = NULL, + ymeasures = NULL, + columns = c("xgroups", "p"), + listwise.deletion = FALSE, + sep.char = ", ", + xlevels = NULL, + yvarlabels = NULL, + ylevels = NULL, + indent.spaces = 3, + latex = TRUE, + decimals = NULL, + formatp.list = NULL, + n.headings = FALSE, + N.headings = FALSE, + print.html = FALSE, + html.filename = "table1.html", + tabmeans.svy.list = NULL, + tabmedians.svy.list = NULL, + tabfreq.svy.list = NULL +) } \arguments{ \item{formula}{Formula, e.g. \code{Age + Race + BMI ~ Sex}.} diff --git a/man/tabreg.Rd b/man/tabreg.Rd index 8c2f5c9..c0e1056 100644 --- a/man/tabreg.Rd +++ b/man/tabreg.Rd @@ -4,9 +4,18 @@ \alias{tabreg} \title{Create Regression Table from Betas and Standard Errors} \usage{ -tabreg(betas, ses = NULL, varcov = NULL, columns = c("beta.se", "p"), - sep.char = ", ", decimals = NULL, formatp.list = NULL, - labels = NULL, print.html = FALSE, html.filename = "table1.html") +tabreg( + betas, + ses = NULL, + varcov = NULL, + columns = c("beta.se", "p"), + sep.char = ", ", + decimals = NULL, + formatp.list = NULL, + labels = NULL, + print.html = FALSE, + html.filename = "table1.html" +) } \arguments{ \item{betas}{Numeric vector.}