Skip to content

Commit

Permalink
Merge branch 'rc0.4.0'
Browse files Browse the repository at this point in the history
Conflicts:
	NEWS
  • Loading branch information
kaz-yos committed Mar 30, 2014
2 parents ee3a953 + 7aec132 commit a255085
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 33 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Package: tableone
Type: Package
Title: Create "Table 1" to describe baseline characteristics
Version: 0.3.5
Date: 2014-03-07
Author: Kazuki Yoshida, Justin Bohn
Version: 0.4.0
Date: 2014-03-30
Author: Kazuki Yoshida, Justin Bohn.
Maintainer: Kazuki Yoshida <[email protected]>
Description: This package creates "Table 1", i.e., description of baseline
patient characteristics, which is essential in every medical research. This
Expand Down
12 changes: 12 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
tableone 0.4.0 (2014-03-30)
----------------------------------------------------------------

NEW FEATURES

* The showAllLevels argument to show all levels of categorical
variables regardless of numbers of levels was added to
print.TableOne. Previously, it was only available in
print.CatTable. To accommodate this feature, insertLevel argument
to insert an empty level column was added to print.ContTable.


tableone 0.3.5 (2014-03-07)
----------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion R/print.CatTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
##' @param explain Whether to add explanation to the variable names, i.e., (\%) is added to the variable names when percentage is shown.
##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned.
##' @param format The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency).
##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid
##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information.
##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row.
##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.
##' @param exact A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test).
Expand Down
26 changes: 17 additions & 9 deletions R/print.ContTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned.
##' @param nonnormal A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test).
##' @param minMax Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE.
##' @param insertLevel Whether to add an empty level column to the left of strata.
##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.
##' @param ... For compatibility with generic. Ignored.
##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it.
Expand Down Expand Up @@ -77,18 +78,19 @@
##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE)
##'
##' @export
print.ContTable <- function(x, # ContTable object
digits = 2, pDigits = 3, # Number of digits to show
quote = FALSE, # Whether to show quotes
print.ContTable <- function(x, # ContTable object
digits = 2, pDigits = 3, # Number of digits to show
quote = FALSE, # Whether to show quotes

missing = FALSE, # show missing values (not implemented yet)
explain = TRUE, # Whether to show explanation in variable names
printToggle = TRUE, # Whether to print the result visibly
missing = FALSE, # show missing values (not implemented yet)
explain = TRUE, # Whether to show explanation in variable names
printToggle = TRUE, # Whether to print the result visibly

nonnormal = NULL, # Which variables should be treated as nonnormal
minMax = FALSE, # median [range] instead of median [IQR]
nonnormal = NULL, # Which variables should be treated as nonnormal
minMax = FALSE, # median [range] instead of median [IQR]
insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable

test = TRUE, # Whether to add p-values
test = TRUE, # Whether to add p-values

...) {

Expand Down Expand Up @@ -286,6 +288,12 @@ print.ContTable <- function(x, # ContTable object
## Put back the column names (overkill for non-multivariable cases)
colnames(out) <- outColNames

## Add the level column if requested
if (insertLevel) {
out <- cbind(level = rep("", nrow(out)),
out)
}

## Add stratification information to the column header depending on the dimension
names(dimnames(out)) <- ModuleReturnDimHeaders(ContTable)

Expand Down
48 changes: 32 additions & 16 deletions R/print.TableOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned.
##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.
##' @param format The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency).
##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information.
##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row.
##' @param exact A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test).
##' @param nonnormal A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test).
Expand Down Expand Up @@ -69,23 +70,24 @@
##' @export
print.TableOne <- function(x, # TableOne object
catDigits = 1, contDigits = 2, pDigits = 3, # Number of digits to show
quote = FALSE, # Whether to show quotes
quote = FALSE, # Whether to show quotes

## Common options
missing = FALSE, # Not implemented yet
explain = TRUE, # Whether to show explanation in variable names
printToggle = TRUE, # Whether to print the result visibly
test = TRUE, # Whether to add p-values
missing = FALSE, # Not implemented yet
explain = TRUE, # Whether to show explanation in variable names
printToggle = TRUE, # Whether to print the result visibly
test = TRUE, # Whether to add p-values

## Categorical options
format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent
cramVars = NULL, # Which 2-level variables to show both levels in one row
exact = NULL, # Which variables should be tested with exact tests
format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent
showAllLevels = FALSE, # Show all levels of a categorical variable
cramVars = NULL, # Which 2-level variables to show both levels in one row
exact = NULL, # Which variables should be tested with exact tests

## Continuous options
nonnormal = NULL, # Which variables should be treated as nonnormal
minMax = FALSE, # Whether to show median
nonnormal = NULL, # Which variables should be treated as nonnormal
minMax = FALSE, # Whether to show median

...) {

## Get the mixed element only
Expand All @@ -100,14 +102,17 @@ print.TableOne <- function(x, # TableOne object
formattedTables <- sapply(seq_along(TableOne),
FUN = function(i) {

## print.CatTable or print.ContTable called depending on the class
print(TableOne[[i]], printToggle = FALSE, test = test, explain = explain,
digits = digits[i],

## print.CatTable arguments
format = format, exact = exact,
showAllLevels = FALSE, # must be FALSE to get same column counts
showAllLevels = showAllLevels, # Returns one more column if TRUE
cramVars = cramVars,

## print.ContTable argument
nonnormal = nonnormal, minMax = minMax
nonnormal = nonnormal, minMax = minMax, insertLevel = showAllLevels
) # Method dispatch at work
},
simplify = FALSE)
Expand Down Expand Up @@ -142,11 +147,22 @@ print.TableOne <- function(x, # TableOne object
matObj <- formattedTables[[i]]
nSpaces <- nSpacesToAdd[, i]

## For j-th stratum (column). Be aware of the p-value column
## For j-th stratum (column), add spaces.
## Be aware of the p-value column (last. not included in first palce)
## and level column (1st. explicitly ignore).
for (j in seq_along(nSpaces)) {

matObj[, j] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""),
matObj[, j])
## If showAllLevels is requested, ignore the first column (level column).
if (showAllLevels) {
matObj[, (j + 1)] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""),
matObj[, (j + 1)])

} else {
## if not, no need to ignore the first column
matObj[, j] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""),
matObj[, j])
}

}

## Return the adjusted table
Expand Down
3 changes: 2 additions & 1 deletion man/print.CatTable.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

\item{showAllLevels}{Whether to show all levels. FALSE by
default, i.e., for 2-level categorical variables, only
the higher level is shown to avoid}
the higher level is shown to avoid redundant
information.}

\item{cramVars}{A character vector to specify the
two-level categorical variables, for which both levels
Expand Down
5 changes: 4 additions & 1 deletion man/print.ContTable.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\usage{
\method{print}{ContTable}(x, digits = 2, pDigits = 3, quote = FALSE,
missing = FALSE, explain = TRUE, printToggle = TRUE, nonnormal = NULL,
minMax = FALSE, test = TRUE, ...)
minMax = FALSE, insertLevel = FALSE, test = TRUE, ...)
}
\arguments{
\item{x}{The result of a call to the
Expand Down Expand Up @@ -38,6 +38,9 @@
\item{minMax}{Whether to use [min,max] instead of
[p25,p75] for nonnormal variables. The default is FALSE.}

\item{insertLevel}{Whether to add an empty level column
to the left of strata.}

\item{test}{Whether to show the p-values. TRUE by
default. If FALSE, only the numerical summaries are
shown.}
Expand Down
9 changes: 7 additions & 2 deletions man/print.TableOne.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
\usage{
\method{print}{TableOne}(x, catDigits = 1, contDigits = 2, pDigits = 3,
quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE,
test = TRUE, format = c("fp", "f", "p", "pf")[1], cramVars = NULL,
exact = NULL, nonnormal = NULL, minMax = FALSE, ...)
test = TRUE, format = c("fp", "f", "p", "pf")[1], showAllLevels = FALSE,
cramVars = NULL, exact = NULL, nonnormal = NULL, minMax = FALSE, ...)
}
\arguments{
\item{x}{The result of a call to the
Expand Down Expand Up @@ -44,6 +44,11 @@
You can also choose from "f" frequency only, "p"
percentage only, and "pf" percentage (frequency).}

\item{showAllLevels}{Whether to show all levels. FALSE by
default, i.e., for 2-level categorical variables, only
the higher level is shown to avoid redundant
information.}

\item{cramVars}{A character vector to specify the
two-level categorical variables, for which both levels
should be shown in one row.}
Expand Down

0 comments on commit a255085

Please sign in to comment.