From cc1933630520231a5bf3e8c73d1a609b4dfd1769 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 13 Feb 2014 20:43:58 -0500 Subject: [PATCH 01/12] doc fixed for 0.2.0rc --- DESCRIPTION | 9 ++------- NEWS | 15 +++++++++++++-- R/tableone-package.R | 13 +++++-------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a474fbb..ed26f0d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,15 +2,10 @@ Package: tableone Type: Package Title: Create the "Table 1" to describe baseline characteristics Version: 0.2.0 -Date: 2014-02-12 +Date: 2014-02-13 Author: Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida -Description: This package creates create the "Table1", i.e., - description of baseline characteristics in R although it is - essential in every medical research. The package was insipired by - and based on descriptive statistics functions in Deducer by Ian Fellows, - a Java-based GUI package. This package does not require GUI or Java, - and intended for CUI users. +Description: This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by descriptive statistics functions in Deducerby Ian Fellows, Java-based GUI package. This package does not require GUI or Java, and intended for CUI users. License: GPL-2 Depends: e1071, diff --git a/NEWS b/NEWS index ee7e6d9..dacfcd9 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,14 @@ -tableone 0.1.3 (not released yet) +tableone 0.2.0 +---------------------------------------------------------------- +NEW FEATURES + +* CreateTableOne and related print/summary methods were added. + +* CreateTableOne can crate a table with both categorical and + continuous variables. + + +tableone 0.1.3 ---------------------------------------------------------------- NEW FEATURES @@ -17,7 +27,8 @@ BUG FIXES * Fixed incorrect specification of S3 method export. -* To make an object an S3 method and export it both at_S3method and at_export tags are needed in the Roxygen part of the code. +* To make an object an S3 method and export it both at_S3method and at_export + tags are needed in the Roxygen part of the code. * Passed all the default tests by R CMD check file.tar.gz diff --git a/R/tableone-package.R b/R/tableone-package.R index ee22aab..52c48a5 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -1,14 +1,9 @@ ##' Create "Table 1" to describe baseline characteristics ##' -##' Table 1, i.e., description of baseline patient characteristics is essential -##' every medical research. This package provides functions to create such -##' summaries for continuous and categorical variables, optionally with subgroups -##' and groupwise comparison. The package was insipired by descriptive statistics -##' functions in Deducer, Java-based GUI package. This package does not require -##' GUI or Java, and intended for CUI users. +##' This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by descriptive statistics functions in Deducerby Ian Fellows, Java-based GUI package. This package does not require GUI or Java, and intended for CUI users. ##' ##' \tabular{ll}{ Package: \tab tableone\cr Type: \tab Package\cr Version: \tab -##' 0.1.3\cr Date: \tab 2014-02-08\cr License: \tab GPL-2\cr } Create an object +##' 0.2.0\cr Date: \tab 2014-02-13\cr License: \tab GPL-2\cr } Create an object ##' summarizing continous and categorical variables optionally stratifying by ##' one or more startifying variables and performing statistical tests. The ##' object gives a table that is easy to use in medical research papers. @@ -20,9 +15,11 @@ ##' @docType package ##' @note Special Thanks: ##' Ian Fellows for developing the Deducer package, which this package is based on. -##' Hadley Wickham for packaging advice and for creating tools this package was made with. +##' +##' Hadley Wickham for packaging advice and for creating tools this package was made with (roxygens, devtools, testthat). ##' ##' Developmental repository is on github. Your contributions are appreciated. +##' ##' https://github.com/kaz-yos/tableone ##' ##' @author Kazuki Yoshida, Justin Bohn From e6bedd3d06842ba0ad95138c7696c7ffcc50066a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 13 Feb 2014 21:03:20 -0500 Subject: [PATCH 02/12] package doc fixed --- DESCRIPTION | 8 ++++- R/tableone-package.R | 45 ++++++++++++------------- man/tableone-package.Rd | 75 ++++++++++++++++++++--------------------- 3 files changed, 65 insertions(+), 63 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ed26f0d..d127f96 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,7 +5,13 @@ Version: 0.2.0 Date: 2014-02-13 Author: Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida -Description: This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by descriptive statistics functions in Deducerby Ian Fellows, Java-based GUI package. This package does not require GUI or Java, and intended for CUI users. +Description: This package creates "Table 1", i.e., description of baseline + patient characteristics, which is essential every medical research. This + package provides functions to create such summaries for continuous and + categorical variables, optionally with subgroups and groupwise comparison. + The package was insipired by descriptive statistics functions in Deducerby + Ian Fellows, Java-based GUI package. This package does not require GUI or + Java, and intended for CUI users. License: GPL-2 Depends: e1071, diff --git a/R/tableone-package.R b/R/tableone-package.R index 52c48a5..3187da0 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -1,22 +1,15 @@ ##' Create "Table 1" to describe baseline characteristics ##' -##' This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by descriptive statistics functions in Deducerby Ian Fellows, Java-based GUI package. This package does not require GUI or Java, and intended for CUI users. -##' -##' \tabular{ll}{ Package: \tab tableone\cr Type: \tab Package\cr Version: \tab -##' 0.2.0\cr Date: \tab 2014-02-13\cr License: \tab GPL-2\cr } Create an object -##' summarizing continous and categorical variables optionally stratifying by -##' one or more startifying variables and performing statistical tests. The -##' object gives a table that is easy to use in medical research papers. -##' Continuous variables are handled by CreateContTable, and categorical -##' variables are handled by CreateCatTable. +##' This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by descriptive statistics functions in Deducer by Ian Fellows, Java-based GUI package. This package does not require GUI or Java, and intended for CUI users. ##' ##' @name tableone-package ##' @aliases tableone-package tableone ##' @docType package ##' @note Special Thanks: +##' ##' Ian Fellows for developing the Deducer package, which this package is based on. ##' -##' Hadley Wickham for packaging advice and for creating tools this package was made with (roxygens, devtools, testthat). +##' Hadley Wickham for packaging advice and for creating tools this package was made with (roxygen2, devtools, testthat). ##' ##' Developmental repository is on github. Your contributions are appreciated. ##' @@ -41,22 +34,26 @@ ##' ## Check variables ##' head(pbc) ##' -##' ## Create an overall table for categorical variables -##' catVars <- c("status","ascites","hepato","spiders","edema","stage") -##' catTableOverall <- CreateCatTable(vars = catVars, data = pbc) +##' ## Make categorical variables factors +##' varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") +##' pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) +##' +##' ## Create Table 1 stratified by sex and trt +##' tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", +##' "spiders","edema","bili","chol","albumin", +##' "copper","alk.phos","ast","trig","platelet", +##' "protime","stage"), +##' strata = c("sex","trt"), data = pbc) ##' -##' ## Simply typing the object name will invoke the print.CatTable method, -##' ## which will show the sample size, frequencies and percentages. -##' ## For 2-level variables, only the higher level is shown for simplicity. -##' catTableOverall +##' ## Just typing the object name will invoke the print.TableOne method +##' tableOne ##' -##' ## Create an overall table for continuous variables -##' contVars <- c("time","age","bili","chol","albumin","copper","alk.phos","ast", -##' "trig","platelet","protime") -##' contTableOverall <- CreateContTable(vars = contVars, data = pbc) +##' ## Specifying nonnormal variables will show the variables appropriately, +##' ## and show nonparametric test p-values. Specify variables in the exact +##' ## argument to obtain the exact test p-values. +##' print(tableOne, nonnormal = c("time"), exact = c("ascites")) ##' -##' ## Simply typing the object name will invoke the print.ContTable method, -##' ## which will show the sample size, means and standard deviations. -##' contTableOverall +##' ## Use the summary.TableOne method for depth summary +##' summary(tableOne) ##' NULL diff --git a/man/tableone-package.Rd b/man/tableone-package.Rd index 0ff0fc6..9140229 100644 --- a/man/tableone-package.Rd +++ b/man/tableone-package.Rd @@ -4,34 +4,29 @@ \alias{tableone-package} \title{Create "Table 1" to describe baseline characteristics} \description{ -Table 1, i.e., description of baseline patient -characteristics is essential every medical research. This -package provides functions to create such summaries for -continuous and categorical variables, optionally with -subgroups and groupwise comparison. The package was -insipired by descriptive statistics functions in Deducer, -Java-based GUI package. This package does not require GUI -or Java, and intended for CUI users. -} -\details{ -\tabular{ll}{ Package: \tab tableone\cr Type: \tab -Package\cr Version: \tab 0.1.3\cr Date: \tab 2014-02-08\cr -License: \tab GPL-2\cr } Create an object summarizing -continous and categorical variables optionally stratifying -by one or more startifying variables and performing -statistical tests. The object gives a table that is easy to -use in medical research papers. Continuous variables are -handled by CreateContTable, and categorical variables are -handled by CreateCatTable. +This package creates "Table 1", i.e., description of +baseline patient characteristics, which is essential every +medical research. This package provides functions to create +such summaries for continuous and categorical variables, +optionally with subgroups and groupwise comparison. The +package was insipired by descriptive statistics functions +in Deducer by Ian Fellows, Java-based GUI package. This +package does not require GUI or Java, and intended for CUI +users. } \note{ -Special Thanks: Ian Fellows for developing the Deducer -package, which this package is based on. Hadley Wickham for -packaging advice and for creating tools this package was -made with. +Special Thanks: + +Ian Fellows for developing the Deducer package, which this +package is based on. + +Hadley Wickham for packaging advice and for creating tools +this package was made with (roxygens, devtools, testthat). Developmental repository is on github. Your contributions -are appreciated. https://github.com/kaz-yos/tableone +are appreciated. + +https://github.com/kaz-yos/tableone } \examples{ ## Load @@ -43,23 +38,27 @@ data(pbc) ## Check variables head(pbc) -## Create an overall table for categorical variables -catVars <- c("status","ascites","hepato","spiders","edema","stage") -catTableOverall <- CreateCatTable(vars = catVars, data = pbc) +## Make categorical variables factors +varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") +pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) + +## Create Table 1 stratified by sex and trt +tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage"), + strata = c("sex","trt"), data = pbc) -## Simply typing the object name will invoke the print.CatTable method, -## which will show the sample size, frequencies and percentages. -## For 2-level variables, only the higher level is shown for simplicity. -catTableOverall +## Just typing the object name will invoke the print.TableOne method +tableOne -## Create an overall table for continuous variables -contVars <- c("time","age","bili","chol","albumin","copper","alk.phos","ast", - "trig","platelet","protime") -contTableOverall <- CreateContTable(vars = contVars, data = pbc) +## Specifying nonnormal variables will show the variables appropriately, +## and show nonparametric test p-values. Specify variables in the exact +## argument to obtain the exact test p-values. +print(tableOne, nonnormal = c("time"), exact = c("ascites")) -## Simply typing the object name will invoke the print.ContTable method, -## which will show the sample size, means and standard deviations. -contTableOverall +## Use the summary.TableOne method for depth summary +summary(tableOne) } \author{ Kazuki Yoshida, Justin Bohn From 9a00e2a2c91804a1a7864a914066f9f661624e8b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 13 Feb 2014 21:17:43 -0500 Subject: [PATCH 03/12] package doc fix --- DESCRIPTION | 8 +------- R/tableone-package.R | 2 +- man/tableone-package.Rd | 10 +++++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d127f96..11c6ef2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,13 +5,7 @@ Version: 0.2.0 Date: 2014-02-13 Author: Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida -Description: This package creates "Table 1", i.e., description of baseline - patient characteristics, which is essential every medical research. This - package provides functions to create such summaries for continuous and - categorical variables, optionally with subgroups and groupwise comparison. - The package was insipired by descriptive statistics functions in Deducerby - Ian Fellows, Java-based GUI package. This package does not require GUI or - Java, and intended for CUI users. +Description: This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for CUI users. License: GPL-2 Depends: e1071, diff --git a/R/tableone-package.R b/R/tableone-package.R index 3187da0..c079806 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -1,6 +1,6 @@ ##' Create "Table 1" to describe baseline characteristics ##' -##' This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by descriptive statistics functions in Deducer by Ian Fellows, Java-based GUI package. This package does not require GUI or Java, and intended for CUI users. +##' This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for CUI users. ##' ##' @name tableone-package ##' @aliases tableone-package tableone diff --git a/man/tableone-package.Rd b/man/tableone-package.Rd index 9140229..ac2fa5d 100644 --- a/man/tableone-package.Rd +++ b/man/tableone-package.Rd @@ -9,10 +9,10 @@ baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The -package was insipired by descriptive statistics functions -in Deducer by Ian Fellows, Java-based GUI package. This -package does not require GUI or Java, and intended for CUI -users. +package was insipired by and based on descriptive +statistics functions in Deducer by Ian Fellows, Java-based +GUI package. This package does not require GUI or Java, and +intended for CUI users. } \note{ Special Thanks: @@ -21,7 +21,7 @@ Ian Fellows for developing the Deducer package, which this package is based on. Hadley Wickham for packaging advice and for creating tools -this package was made with (roxygens, devtools, testthat). +this package was made with (roxygen2, devtools, testthat). Developmental repository is on github. Your contributions are appreciated. From 0004f7ac849b780eb454fb8da09a0b3faed1622a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 13 Feb 2014 21:23:03 -0500 Subject: [PATCH 04/12] installing non-master branch added to README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index edce3bb..7bb5519 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,10 @@ Alternatively, you can use the devtools to install from github directly. install.packages("devtools") ## Load devtools library(devtools) -## Install directly from github +## Install directly from github (master branch) install_github(repo = "kaz-yos/tableone") +## Install directly from github (rc0.2.0 branch) +install_github(repo = "kaz-yos/tableone", ref = "rc0.2.0") ## Load library(tableone) ``` From 71e8662ff70757353c66c1f877a18361d9a7793c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 13 Feb 2014 21:52:58 -0500 Subject: [PATCH 05/12] TableOne functions doc fix --- DESCRIPTION | 8 +++++++- R/CreateTableOne.R | 9 ++++----- man/CreateTableOne.Rd | 8 +++++--- man/tableone-package.Rd | 6 +++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 11c6ef2..f80830a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,7 +5,13 @@ Version: 0.2.0 Date: 2014-02-13 Author: Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida -Description: This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for CUI users. +Description: This package creates "Table 1", i.e., description of baseline + patient characteristics, which is essential every medical research. This + package provides functions to create such summaries for continuous and + categorical variables, optionally with subgroups and groupwise comparison. + The package was insipired by and based on descriptive statistics functions + in Deducer, a Java-based GUI package by Ian Fellows. This package does not + require GUI or Java, and intended for CUI users. License: GPL-2 Depends: e1071, diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 5493be2..72b6f21 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -1,10 +1,9 @@ -### 2014-02-09 Unifying function suggested by Justin Bohn +##' Create an object summarizing both categorical and continuous variables ##' -##' Create an object|output summarizing both categorical and continuous variables -##' -##' Create an object|output summarizing categorical variables optionally stratifying +##' Create an object summarizing categorical variables optionally stratifying ##' by one or more startifying variables and performing statistical tests. The -##' object gives a table that is easy to use in medical research papers. +##' object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. +##' ##' ##' @param vars Variables to be summarized given as a character vector. Factors are ##' handled as categorical variables, whereas numeric variables are handled as continuous variables. diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index 18cb575..1eee91a 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -1,6 +1,6 @@ \name{CreateTableOne} \alias{CreateTableOne} -\title{Create an object|output summarizing both categorical and continuous variables} +\title{Create an object summarizing both categorical and continuous variables} \usage{ CreateTableOne(vars, strata, data, test = TRUE, testApprox = chisq.test, argsApprox = list(correct = TRUE), testExact = fisher.test, @@ -74,10 +74,12 @@ of two \code{\link{by}} objects with additional attributes. These correspond to structures holding results for } \description{ -Create an object|output summarizing categorical variables +Create an object summarizing categorical variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table -that is easy to use in medical research papers. +that is easy to use in medical research papers. See also +\code{\link{print.TableOne}} and +\code{\link{summary.TableOne}}. } \examples{ ## Load diff --git a/man/tableone-package.Rd b/man/tableone-package.Rd index ac2fa5d..31dbc96 100644 --- a/man/tableone-package.Rd +++ b/man/tableone-package.Rd @@ -10,9 +10,9 @@ medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by and based on descriptive -statistics functions in Deducer by Ian Fellows, Java-based -GUI package. This package does not require GUI or Java, and -intended for CUI users. +statistics functions in Deducer, a Java-based GUI package +by Ian Fellows. This package does not require GUI or Java, +and intended for CUI users. } \note{ Special Thanks: From a5610fd3e27a9324c25cf3013a5391fc19e5f7f1 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 13 Feb 2014 22:14:22 -0500 Subject: [PATCH 06/12] CreateTableOne doc fixed --- R/CreateTableOne.R | 3 +-- man/CreateTableOne.Rd | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 72b6f21..a22f704 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -30,8 +30,7 @@ ##' memory limitation. In this situation, the large sample approximation based ##' should suffice. ##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. -##' @return An object of class \code{TableOne}, which really is a list of two \code{\link{by}} objects with -##' additional attributes. These correspond to structures holding results for +##' @return An object of class \code{TableOne}, which really is a list of three objects. The first object named \code{object$TableOne} is the categorical-continuous mixture table formatted and printed by the \code{\link{print.TableOne}} method. The second object named \code{object$ContTable} is the table object containing continuous variables only. The third object named \code{object$CatTable} is the table object containing categorical variables only. The second and third objects can be then be examined with the \code{print} and \{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. ##' @author Justin Bohn, Kazuki Yoshida ##' @seealso ##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index 1eee91a..8853b5c 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -70,8 +70,18 @@ CreateTableOne(vars, strata, data, test = TRUE, testApprox = chisq.test, } \value{ An object of class \code{TableOne}, which really is a list -of two \code{\link{by}} objects with additional attributes. -These correspond to structures holding results for +of three objects. The first object named +\code{object$TableOne} is the categorical-continuous +mixture table formatted and printed by the +\code{\link{print.TableOne}} method. The second object +named \code{object$ContTable} is the table object +containing continuous variables only. The third object +named \code{object$CatTable} is the table object containing +categorical variables only. The second and third objects +can be then be examined with the \code{print} and +\{summary} method, for example, +\code{summary(object$CatTable)} to examine the categorical +variables in detail. } \description{ Create an object summarizing categorical variables From dfff6dca6b4a32dfa9bf026245165565edc02ab1 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 14 Feb 2014 06:03:11 -0500 Subject: [PATCH 07/12] overall TableOne doc change. CatTable/ContTable access explained --- R/CreateTableOne.R | 26 +++++++++++++++++--------- R/tableone-package.R | 29 +++++++++++++++++++---------- man/CreateTableOne.Rd | 25 +++++++++++++++++-------- man/print.TableOne.Rd | 2 +- man/summary.TableOne.Rd | 2 +- man/tableone-package.Rd | 23 ++++++++++++++++------- man_create.R | 1 + 7 files changed, 72 insertions(+), 36 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index a22f704..84358de 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -4,7 +4,6 @@ ##' by one or more startifying variables and performing statistical tests. The ##' object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. ##' -##' ##' @param vars Variables to be summarized given as a character vector. Factors are ##' handled as categorical variables, whereas numeric variables are handled as continuous variables. ##' @param strata Stratifying (grouping) variable name(s) given as a character @@ -30,7 +29,7 @@ ##' memory limitation. In this situation, the large sample approximation based ##' should suffice. ##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. -##' @return An object of class \code{TableOne}, which really is a list of three objects. The first object named \code{object$TableOne} is the categorical-continuous mixture table formatted and printed by the \code{\link{print.TableOne}} method. The second object named \code{object$ContTable} is the table object containing continuous variables only. The third object named \code{object$CatTable} is the table object containing categorical variables only. The second and third objects can be then be examined with the \code{print} and \{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. +##' @return An object of class \code{TableOne}, which really is a list of three objects. The first object named \code{object$TableOne} is the categorical-continuous mixture table formatted and printed by the \code{\link{print.TableOne}} method. The second object named \code{object$ContTable} is the table object containing continuous variables only. The third object named \code{object$CatTable} is the table object containing categorical variables only. The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. ##' @author Justin Bohn, Kazuki Yoshida ##' @seealso ##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, @@ -51,12 +50,15 @@ ##' varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") ##' pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) ##' -##' ## Create Table 1 stratified by sex and trt -##' tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", -##' "spiders","edema","bili","chol","albumin", -##' "copper","alk.phos","ast","trig","platelet", -##' "protime","stage"), -##' strata = c("sex","trt"), data = pbc) +##' ## Create a variable list +##' dput(names(pbc)) +##' vars <- c("time","status","age","sex","ascites","hepato", +##' "spiders","edema","bili","chol","albumin", +##' "copper","alk.phos","ast","trig","platelet", +##' "protime","stage") +##' +##' ## Create Table 1 stratified by trt +##' tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) ##' ##' ## Just typing the object name will invoke the print.TableOne method ##' tableOne @@ -66,9 +68,15 @@ ##' ## argument to obtain the exact test p-values. ##' print(tableOne, nonnormal = c("time"), exact = c("ascites")) ##' -##' ## Use the summary.TableOne method for depth summary +##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) ##' +##' ## See the categorical part only using $ operator +##' tableOne$CatTable +##' +##' ## See the continuous part only using $ operator +##' tableOne$ContTable +##' ##' @export CreateTableOne <- function(vars, strata, data, diff --git a/R/tableone-package.R b/R/tableone-package.R index c079806..a3b6d7c 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -6,13 +6,13 @@ ##' @aliases tableone-package tableone ##' @docType package ##' @note Special Thanks: -##' +##' ##' Ian Fellows for developing the Deducer package, which this package is based on. -##' +##' ##' Hadley Wickham for packaging advice and for creating tools this package was made with (roxygen2, devtools, testthat). ##' ##' Developmental repository is on github. Your contributions are appreciated. -##' +##' ##' https://github.com/kaz-yos/tableone ##' ##' @author Kazuki Yoshida, Justin Bohn @@ -38,12 +38,15 @@ ##' varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") ##' pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) ##' -##' ## Create Table 1 stratified by sex and trt -##' tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", -##' "spiders","edema","bili","chol","albumin", -##' "copper","alk.phos","ast","trig","platelet", -##' "protime","stage"), -##' strata = c("sex","trt"), data = pbc) +##' ## Create a variable list +##' dput(names(pbc)) +##' vars <- c("time","status","age","sex","ascites","hepato", +##' "spiders","edema","bili","chol","albumin", +##' "copper","alk.phos","ast","trig","platelet", +##' "protime","stage") +##' +##' ## Create Table 1 stratified by trt +##' tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) ##' ##' ## Just typing the object name will invoke the print.TableOne method ##' tableOne @@ -53,7 +56,13 @@ ##' ## argument to obtain the exact test p-values. ##' print(tableOne, nonnormal = c("time"), exact = c("ascites")) ##' -##' ## Use the summary.TableOne method for depth summary +##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) +##' +##' ## See the categorical part only using $ operator +##' tableOne$CatTable +##' +##' ## See the continuous part only using $ operator +##' tableOne$ContTable ##' NULL diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index 8853b5c..53996da 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -79,7 +79,7 @@ containing continuous variables only. The third object named \code{object$CatTable} is the table object containing categorical variables only. The second and third objects can be then be examined with the \code{print} and -\{summary} method, for example, +\code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. } @@ -105,12 +105,15 @@ head(pbc) varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) -## Create Table 1 stratified by sex and trt -tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage"), - strata = c("sex","trt"), data = pbc) +## Create a variable list +dput(names(pbc)) +vars <- c("time","status","age","sex","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage") + +## Create Table 1 stratified by trt +tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) ## Just typing the object name will invoke the print.TableOne method tableOne @@ -120,8 +123,14 @@ tableOne ## argument to obtain the exact test p-values. print(tableOne, nonnormal = c("time"), exact = c("ascites")) -## Use the summary.TableOne method for depth summary +## Use the summary.TableOne method for detailed summary summary(tableOne) + +## See the categorical part only using $ operator +tableOne$CatTable + +## See the continuous part only using $ operator +tableOne$ContTable } \author{ Justin Bohn, Kazuki Yoshida diff --git a/man/print.TableOne.Rd b/man/print.TableOne.Rd index e9c869a..3c763a4 100644 --- a/man/print.TableOne.Rd +++ b/man/print.TableOne.Rd @@ -94,7 +94,7 @@ tableOne ## argument to obtain the exact test p-values. print(tableOne, nonnormal = c("time"), exact = c("ascites")) -## Use the summary.TableOne method for depth summary +## Use the summary.TableOne method for detailed summary summary(tableOne) } \author{ diff --git a/man/summary.TableOne.Rd b/man/summary.TableOne.Rd index 664b141..2407d2f 100644 --- a/man/summary.TableOne.Rd +++ b/man/summary.TableOne.Rd @@ -51,7 +51,7 @@ tableOne ## argument to obtain the exact test p-values. print(tableOne, nonnormal = c("time"), exact = c("ascites")) -## Use the summary.TableOne method for depth summary +## Use the summary.TableOne method for detailed summary summary(tableOne) } \author{ diff --git a/man/tableone-package.Rd b/man/tableone-package.Rd index 31dbc96..fa50250 100644 --- a/man/tableone-package.Rd +++ b/man/tableone-package.Rd @@ -42,12 +42,15 @@ head(pbc) varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) -## Create Table 1 stratified by sex and trt -tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage"), - strata = c("sex","trt"), data = pbc) +## Create a variable list +dput(names(pbc)) +vars <- c("time","status","age","sex","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage") + +## Create Table 1 stratified by trt +tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) ## Just typing the object name will invoke the print.TableOne method tableOne @@ -57,8 +60,14 @@ tableOne ## argument to obtain the exact test p-values. print(tableOne, nonnormal = c("time"), exact = c("ascites")) -## Use the summary.TableOne method for depth summary +## Use the summary.TableOne method for detailed summary summary(tableOne) + +## See the categorical part only using $ operator +tableOne$CatTable + +## See the continuous part only using $ operator +tableOne$ContTable } \author{ Kazuki Yoshida, Justin Bohn diff --git a/man_create.R b/man_create.R index d4a7fd5..ac0607d 100644 --- a/man_create.R +++ b/man_create.R @@ -1,3 +1,4 @@ +## !/usr/bin/Rscript ################################################################################ ### .Rd creater ## Creates .Rd from in-source Roxygen2 docs in .R files From 6aee79966205ee2b12df0fd61438a66cb7be0e0c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 14 Feb 2014 06:04:37 -0500 Subject: [PATCH 08/12] additional doc fix --- R/summary.TableOne.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/summary.TableOne.R b/R/summary.TableOne.R index 18698ff..fddf893 100644 --- a/R/summary.TableOne.R +++ b/R/summary.TableOne.R @@ -45,7 +45,7 @@ ##' ## argument to obtain the exact test p-values. ##' print(tableOne, nonnormal = c("time"), exact = c("ascites")) ##' -##' ## Use the summary.TableOne method for depth summary +##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) ##' ##' @export From 14832690f0618a9a9421cea0598f4bd63cec97f6 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 14 Feb 2014 06:17:20 -0500 Subject: [PATCH 09/12] add stratification info. Avoid NA when not stratified --- R/print.CatTable.R | 6 +++++- R/print.ContTable.R | 6 +++++- R/print.TableOne.R | 35 ++++++++++++++++------------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index 61e66d1..04cac71 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -456,11 +456,15 @@ print.CatTable <- function(x, missing = FALSE, ## Name the row dimension with it. 1st dimension name should be empty. names(dimnames(out)) <- c("", strataString) + } else { + + names(dimnames(out)) <- c("", "") } ## Modular version of quote/print toggle. - out <- ModuleQuoteAndPrintMat(matObj = out, quote = quote, printToggle = printToggle) + out <- ModuleQuoteAndPrintMat(matObj = out, + quote = quote, printToggle = printToggle) ## Print CrossTable() if requested if (CrossTable) { diff --git a/R/print.ContTable.R b/R/print.ContTable.R index a7945a2..146aedc 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -349,11 +349,15 @@ print.ContTable <- function(x, missing = FALSE, ## Name the row dimension with it. 1st dimension name should be empty. names(dimnames(out)) <- c("", strataString) + } else { + + names(dimnames(out)) <- c("", "") } ## (module) Takes an matrix object format, print if requested - out <- ModuleQuoteAndPrintMat(matObj = out, quote = quote, printToggle = printToggle) + out <- ModuleQuoteAndPrintMat(matObj = out, + quote = quote, printToggle = printToggle) ## Add attributes for column widths in characters attributes(out) <- c(attributes(out), diff --git a/R/print.TableOne.R b/R/print.TableOne.R index ce0e86d..9aa62e3 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -67,7 +67,7 @@ ##' ## argument to obtain the exact test p-values. ##' print(tableOne, nonnormal = c("time"), exact = c("ascites")) ##' -##' ## Use the summary.TableOne method for depth summary +##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) ##' ##' @export @@ -163,6 +163,21 @@ print.TableOne <- function(x, missing = FALSE, ## Row-combin n and all variables out <- do.call(rbind, c(list(stratumSizesRow), spaceFormattedTables)) + ## Add stratification information to the column header (This is also in the constructor) + if (length(TableOne[[1]]) > 1 ) { + ## Combine variable names with : in between + strataVarName <- attributes(TableOne[[1]])$strataVarName + + ## Create strata string + strataString <- paste0("Stratified by ", strataVarName) + + ## Name the row dimension with it. 1st dimension name should be empty. + names(dimnames(out)) <- c("", strataString) + } else { + + names(dimnames(out)) <- c("", "") + } + ## Modular version of quote/print toggle. out <- ModuleQuoteAndPrintMat(matObj = out, quote = quote, printToggle = printToggle) @@ -170,21 +185,3 @@ print.TableOne <- function(x, missing = FALSE, ## Return the result return(invisible(out)) } - - - - - - - - - - - - - - - - - - From acdb5df9e37ce482e2936b23bd4316795e503a45 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 14 Feb 2014 06:57:55 -0500 Subject: [PATCH 10/12] code formatting aesthetics only --- R/modules.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/modules.R b/R/modules.R index db7f5f1..906d9b1 100644 --- a/R/modules.R +++ b/R/modules.R @@ -35,7 +35,7 @@ ModuleStopIfNoVarsLeft <- function(vars) { ## ModuleReturnFalseIfNoStrata <- function(strata, test) { # Give strata variable names - if(missing(strata)){ + if(missing(strata)) { ## test cannot be performed if no strata test <- FALSE } @@ -44,7 +44,7 @@ ModuleReturnFalseIfNoStrata <- function(strata, test) { # Give strata variable n ## Check statra variables and conditionally create ModuleReturnStrata <- function(strata, data, dat) { # Give strata variable names - if(missing(strata)){ + if(missing(strata)) { ## If there is no strata, give "Overall" to every subject strata <- rep("Overall", dim(dat)[1]) # Check if dim(dat)[[1]] is correct. } else { @@ -107,7 +107,7 @@ ModuleCreateStrataVarName <- function(obj) { ## Used to define non-failing functions, that return NA when there is an error tryCatch.W.E <- function(expr) { W <- NULL - w.handler <- function(w){ # warning handler + w.handler <- function(w) { # warning handler W <<- w invokeRestart("muffleWarning") } From 9f206afc57b319f87095430f7fd4c042fb6dd8d6 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 14 Feb 2014 06:58:17 -0500 Subject: [PATCH 11/12] conditional strata argument. not functional yet --- R/CreateTableOne.R | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 84358de..845c3f9 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -79,7 +79,9 @@ ##' ##' @export CreateTableOne <- - function(vars, strata, data, + function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame test = TRUE, # whether to put p-values ## Test configuration for categorical data testApprox = chisq.test, # function for approximation test @@ -103,6 +105,9 @@ CreateTableOne <- ## Abort if no variables exist at this point ModuleStopIfNoVarsLeft(vars) + ## Toggle test FALSE if no strata is given + test <- ModuleReturnFalseIfNoStrata(strata, test) + ## Get the classes of the variables varClasses <- sapply(data[vars], class) varFactors <- names(varClasses[varClasses == "factor"]) @@ -112,20 +117,26 @@ CreateTableOne <- logiFactors <- sapply(data[vars], is.factor) ## Create lists of arguments - argsCreateContTable <- list(strata = strata, data = data, - test = test, - testNormal = testNormal, - argsNormal = argsNormal, + argsCreateContTable <- list(data = data, + test = test, + testNormal = testNormal, + argsNormal = argsNormal, testNonNormal = testNonNormal, argsNonNormal = argsNonNormal ) - argsCreateCatTable <- list(strata = strata, data = data, - test = test, - testApprox = testApprox, - argsApprox = argsApprox, - testExact = testExact, - argsExact = argsExact + argsCreateCatTable <- list(data = data, + test = test, + testApprox = testApprox, + argsApprox = argsApprox, + testExact = testExact, + argsExact = argsExact ) + ## Add strata = strata for argument only if strata is given + if(!missing(strata)) { + + argsCreateContTable <- c(list(strata = strata), argsCreateContTable) + argsCreateCatTable <- c(list(strata = strata), argsCreateCatTable) + } ## Condition on the absence of factor/numeric @@ -178,8 +189,8 @@ CreateTableOne <- ContTable <- do.call(CreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) ## Aggregated CatTable - CatTable <- do.call(CreateCatTable, - args = c(list(vars = varFactors), argsCreateCatTable)) + CatTable <- do.call(CreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) ## Create a list listOfTables <- list(TableOne = TableOne, From d64aaaf6b09048ed3c4cb5a71557a531883b3dd2 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 14 Feb 2014 07:03:26 -0500 Subject: [PATCH 12/12] sapply simplify avoided to create a matrix with only one stratum (overall) --- R/print.TableOne.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 9aa62e3..29b0bde 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -115,7 +115,8 @@ print.TableOne <- function(x, missing = FALSE, attributes(matObj)$vecColWidths }, - simplify = TRUE) + simplify = FALSE) + columnWidthInfo <- do.call(cbind, columnWidthInfo) ## Get the max values for each stratum vecMaxValues <- apply(columnWidthInfo, MARGIN = 1, FUN = max, na.rm = TRUE)