Skip to content

Commit

Permalink
summarize:
Browse files Browse the repository at this point in the history
- added argument "labels"
- use \endhead if longtables are printed (fixes #20)
  • Loading branch information
hofnerb committed Nov 25, 2015
1 parent 4934840 commit 158e8a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
18 changes: 13 additions & 5 deletions R/summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## define summarize
summarize <- summarise <- function(data, type = c("numeric", "factor"),
variables = names(data), variable.labels = NULL, group = NULL,
variables = names(data), variable.labels = labels, labels = NULL, group = NULL,
test = !is.null(group), colnames = NULL, digits = NULL, digits.pval = 3,
smallest.pval = 0.001, sep = NULL, sanitize = TRUE, drop = TRUE,
show.NAs = any(is.na(data[, variables])), ...) {
Expand Down Expand Up @@ -62,7 +62,7 @@ latex.table.fac <- function(...,
################################################################################
# LaTeX Tables with Descriptves for Continuous Variables
summarize_numeric <- function(data, variables = names(data),
variable.labels = NULL, group = NULL,
variable.labels = labels, labels = NULL, group = NULL,
test = !is.null(group), colnames = NULL,
digits = 2, digits.pval = 3,
smallest.pval = 0.001, sep = !is.null(group),
Expand Down Expand Up @@ -299,7 +299,7 @@ prettify.summarize.numeric <- function(x,
################################################################################
# LaTeX Tables with Descriptves for Factor Variables
summarize_factor <- function(data, variables = names(data),
variable.labels = NULL, group = NULL,
variable.labels = labels, labels = NULL, group = NULL,
test = !is.null(group),
colnames = NULL, digits = 3, digits.pval = 3,
smallest.pval = 0.001, sep = TRUE, sanitize = TRUE,
Expand Down Expand Up @@ -571,6 +571,12 @@ print.xtable.summary <- function(x, rules = NULL, header = NULL,
"", get_option(x, "header"))
header <- ifelse(is.null(header), tmp, header)

## add endhead for longtables
endhead <- ""
if ("tabular.environment" %in% names(list(...)) &&
list(...)$tabular.environment == "longtable")
endhead <- "\\endhead\n"

## sanitize object?
if (is.logical(sanitize.text.function)) {
if (!sanitize.text.function) {
Expand All @@ -586,10 +592,12 @@ print.xtable.summary <- function(x, rules = NULL, header = NULL,
} else {
pos.rules <- 0
}
## add endhead to first rule
midrules <- rep(rules, length(pos.rules))
midrules[1] <- paste(midrules[1], endhead)
add.to.row <- list(pos = as.list(c(-1, -1, pos.rules, nrow(x))),
command = c("\\toprule\n", header,
rep(rules, length(pos.rules)),
"\\bottomrule\n"))
midrules, "\\bottomrule\n"))
}

print.xtable(x,
Expand Down
7 changes: 4 additions & 3 deletions man/summarize.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
\usage{
summarize(data, type = c("numeric", "factor"),
variables = names(data), variable.labels = NULL,
variables = names(data), variable.labels = labels, labels = NULL,
group = NULL, test = !is.null(group), colnames = NULL,
digits = NULL, digits.pval = 3, smallest.pval = 0.001,
sep = NULL, sanitize = TRUE, drop = TRUE,
Expand All @@ -31,10 +31,11 @@ summarize(data, type = c("numeric", "factor"),
table. Per default, all numeric or factor variables of \code{data}
are used, depending on \code{type}.
}
\item{variable.labels}{
\item{variable.labels, labels}{
labels for the variables. If \code{variable.labels = NULL} (default)
\code{variables} is used as label. If \code{variable.labels = TRUE},
\code{labels(data, which = variables)} is used as labels.
\code{labels(data, which = variables)} is used as labels. Instead of
\code{variable.labels} one can also use \code{labels}.
}
\item{group}{
character specifying a grouping factor. Per default no grouping is
Expand Down
4 changes: 2 additions & 2 deletions man/summarize_factor.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
\usage{
summarize_factor(data,
variables = names(data), variable.labels = NULL,
variables = names(data), variable.labels = labels, labels = NULL,
group = NULL, test = !is.null(group), colnames = NULL,
digits = 3, digits.pval = 3, smallest.pval = 0.001,
sep = TRUE, sanitize = TRUE, drop = TRUE,
Expand All @@ -28,7 +28,7 @@ summarize_factor(data,
variables that should be included in the table.
For details see \code{\link{summarize}}.
}
\item{variable.labels}{
\item{variable.labels, labels}{
labels for the variables.
For details see \code{\link{summarize}}.
}
Expand Down
4 changes: 2 additions & 2 deletions man/summarize_numeric.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
\usage{
summarize_numeric(data,
variables = names(data), variable.labels = NULL,
variables = names(data), variable.labels = labels, labels = NULL,
group = NULL, test = !is.null(group), colnames = NULL,
digits = 2, digits.pval = 3, smallest.pval = 0.001,
sep = !is.null(group), sanitize = TRUE,
Expand All @@ -28,7 +28,7 @@ summarize_numeric(data,
variables that should be included in the table.
For details see \code{\link{summarize}}.
}
\item{variable.labels}{
\item{variable.labels, labels}{
labels for the variables.
For details see \code{\link{summarize}}.
}
Expand Down

0 comments on commit 158e8a3

Please sign in to comment.