From e6d88c38bb0308f515642baf46ec111d7b097d73 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 28 Feb 2014 09:36:11 -0500 Subject: [PATCH 01/12] handling of all-NA/NaN variables added. These are dropped --- DESCRIPTION | 4 ++-- NEWS | 12 +++++++++++- R/modules.R | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 42558dc..f63245b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: tableone Type: Package Title: Create "Table 1" to describe baseline characteristics -Version: 0.3.3 -Date: 2014-02-22 +Version: 0.3.4 +Date: 2014-02-28 Author: Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida Description: This package creates "Table 1", i.e., description of baseline diff --git a/NEWS b/NEWS index 2f9b44f..cef8a34 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,13 @@ +tableone 0.3.4 (2014-02-28) +---------------------------------------------------------------- + +BUG FIXES + +* Added the Create* functions handling of all NA/NaN variables. + These invalid variables are examined at the beginning and dropped + with warning for safety. + + tableone 0.3.3 (2014-02-22) ---------------------------------------------------------------- @@ -91,7 +101,7 @@ BUG FIXES * This version is to better conform to the CRAN standards. -* Documents are now included in +* Documents are now included in tableone 0.1.0 (2014-02-08) diff --git a/R/modules.R b/R/modules.R index 79afb72..6448f1d 100644 --- a/R/modules.R +++ b/R/modules.R @@ -16,6 +16,7 @@ ModuleStopIfNotDataFrame <- function(data) { } ## Extract variables that exist in the data frame +## Also exclude variables that only have NA ModuleReturnVarsExist <- function(vars, data) { ## Check if variables exist. Drop them if not. @@ -27,7 +28,22 @@ ModuleReturnVarsExist <- function(vars, data) { ## Only keep variables that exist vars <- intersect(vars, names(data)) } - ## Return existing variables + + ## Check if variables have at least some valid values (not NA/NaN) + logiAllNaVars <- sapply(X = data[vars], + FUN = function(VAR) { + all(is.na(VAR)) + }, + simplify = TRUE) + + if (any(logiAllNaVars)) { + warning("These variables only have NA/NaN: ", + paste0(vars[logiAllNaVars], sep = " "), " Dropped") + + vars <- vars[!logiAllNaVars] + } + + ## Return existing and valid variables return(vars) } From 100d61d641363dea9979d7fd541413a3a979f2c9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Mar 2014 09:08:21 -0500 Subject: [PATCH 02/12] README.md changed for developmental repo --- README.md | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 592150b..8f7ffba 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -tableone +tableone (developmental repo) =============================================================================== **An R package to create "Table 1", description of baseline characteristics** @@ -55,45 +55,18 @@ See also the demonstration here: http://rpubs.com/kaz_yos/tableone-demo-e Installation ------------------------------------------------------------------------------- -The tableone package for R is still in development, and is not available from the CRAN, yet. You can install it using one of the following ways. +This version of tableone package for R is developmetal, and is not available from the CRAN. You can install it using one of the following way. -The archive file for point releases are available from the following URL: +**Direct installation from github** -- https://github.com/kaz-yos/tableone/releases - -**Console method** -In OS X and Linux, after downloading this .tar.gz file, it can be installed from the terminal (Mac: Terminal.app) by doing: - -``` -$ R CMD install tableone_0.2.0_20140214.tar.gz # (or what ever the current version is) -``` - -In Windows, you should be able to do the same in the console. If it does not work please install the Rtools (http://cran.r-project.org/bin/windows/Rtools/). - -``` -> R CMD install tableone_0.2.0_20140214.tar.gz -``` - -**R method 1** -From within R, you can also use the install.packages() function as follows. - -``` -> install.packages("~/statistics/package_development/tableone_0.2.0_20140214.tar.gz", repos = NULL, type = "source") -``` - -You need to change "~/statistics/package_development/tableone_0.2.0_20140214.tar.gz" part to the directory where you have the file.edit - -**R method 2** -Yet another way to install it is installation from github repository. You first need to install the devtools package to do the following. You can choose from the latest stable version and the latest development version. +You first need to install the devtools package to do the following. You can choose from the latest stable version and the latest development version. ``` ## Install devtools (if you do not have it already) > install.packages("devtools") ## Load devtools > library(devtools) -## Install directly from github (master (stable) branch) -> install_github(repo = "kaz-yos/tableone") ## Install directly from github (develop branch) -> install_github(repo = "kaz-yos/tableone", ref = "develop") # If you want the latest +> install_github(repo = "kaz-yos/tableone", ref = "develop") ``` Using devtools requires some preparation, please see the following link for information. From 19e03ce68b8e892f4bb0b39a5f8da86a564b63c8 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Mar 2014 20:48:17 -0500 Subject: [PATCH 03/12] compile.sh shell script added for doc creation/building/testing --- .Rbuildignore | 2 ++ compile.sh | 39 +++++++++++++++++++++++++++++++++++++++ man_create.R | 7 ++++++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 compile.sh mode change 100644 => 100755 man_create.R diff --git a/.Rbuildignore b/.Rbuildignore index acd68d7..fb4aeb1 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,6 +6,8 @@ README.md ## Avoid these temporary scripts +Makefile +compile.sh clean_comments.sh man_create.R man/Rd2roxygen.R diff --git a/compile.sh b/compile.sh new file mode 100755 index 0000000..6d032cb --- /dev/null +++ b/compile.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +## Set package name +pkgName="tableone" + +## build documents (load methods and utils explicitly) +echo "################################################################################" +echo "creating .rd files" +# echo "running ./man_create.R" +echo "" +# ./man_create.R +Rscript -e 'library(methods); library(utils); devtools::document("../tableone/"); devtools::check_doc("../tableone/")' + + +## build a package +echo "" +echo "################################################################################" +echo "building" +echo "" +cd ../ +R CMD build ./tableone + +## run tests on the latest archive file +echo "" +echo "################################################################################" +archiveName=`find tableone_*.tar.gz | tail -n 1` +echo "checking ${archiveName}" +echo "" +R CMD check --as-cran ${archiveName} + +## open the test +echo "" +echo "################################################################################" +echo "opening test results" +echo "" +open ./tableone.Rcheck + +## get back to the same directory +cd ./tableone diff --git a/man_create.R b/man_create.R old mode 100644 new mode 100755 index ac0607d..341f319 --- a/man_create.R +++ b/man_create.R @@ -1,4 +1,5 @@ -## !/usr/bin/Rscript +#!/usr/bin/Rscript + ################################################################################ ### .Rd creater ## Creates .Rd from in-source Roxygen2 docs in .R files @@ -6,11 +7,15 @@ ## Author: Kazuki Yoshida ################################################################################ +## How to make it work with Rscript (load methods and utils explicitly) +## http://stackoverflow.com/questions/8964515/cannot-call-roxygenize-function-from-rscript-batch-file ### Prepare environment ################################################################################ ### Load packages +library(methods) +library(utils) library(devtools) From 565daac3bd7a48c1238786ef7cb6bc1aa0f15986 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Mar 2014 20:50:56 -0500 Subject: [PATCH 04/12] Makefile by Andrew Redd added --- Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..198b384 --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +# Makefile for generating R packages. +# 2011 Andrew Redd +# +# Assumes Makefile is in a folder where package contents are in a subfolder pkg. +# Roxygen uses the roxygen2 package, and will run automatically on check and all. + +PKG_VERSION=$(shell grep -i ^version pkg/DESCRIPTION | cut -d : -d \ -f 2) +PKG_NAME=$(shell grep -i ^package pkg/DESCRIPTION | cut -d : -d \ -f 2) + +R_FILES := $(wildcard pkg/R/*.R) +SRC_FILES := $(wildcard pkg/src/*) $(addprefix pkg/src/, $(COPY_SRC)) +PKG_FILES := pkg/DESCRIPTION pkg/NAMESPACE $(R_FILES) $(SRC_FILES) + +.PHONY: tarball install check clean build + +tarball: $(PKG_NAME)_$(PKG_VERSION).tar.gz +$(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES) + R CMD build pkg + + +check: $(PKG_NAME)_$(PKG_VERSION).tar.gz + R CMD check $(PKG_NAME)_$(PKG_VERSION).tar.gz + +build: $(PKG_NAME)_$(PKG_VERSION).tar.gz + R CMD INSTALL --build $(PKG_NAME)_$(PKG_VERSION).tar.gz + +install: $(PKG_NAME)_$(PKG_VERSION).tar.gz + R CMD INSTALL $(PKG_NAME)_$(PKG_VERSION).tar.gz + +pkg/NAMESPACE: $(R_FILES) + Rscript -e "library(roxygen2);roxygenize('pkg')" + +clean: + -rm -f $(PKG_NAME)_*.tar.gz + -rm -r -f $(PKG_NAME).Rcheck + -rm -r -f pkg/man/* + -rm -r -f pkg/NAMESPACE +.PHONY: list +list: + @echo "R files:" + @echo $(R_FILES) + @echo "Source files:" + @echo $(SRC_FILES) From 510018bf3648983dcfcca7ae41a953c271bfc0c9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Mar 2014 22:09:20 -0500 Subject: [PATCH 05/12] functioning Makefile (creates files within the package dir, use .Rbuildignore) --- .Rbuildignore | 12 +++------ Makefile | 73 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index fb4aeb1..eff3cf6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,14 +8,8 @@ README.md ## Avoid these temporary scripts Makefile compile.sh -clean_comments.sh man_create.R man/Rd2roxygen.R - -## Exclude TableOne related functions -## R/CreateTableOne.R -## R/summary.TableOne.R -## R/print.TableOne.R -## man/CreateTableOne.Rd -## man/summary.TableOne.Rd -## man/print.TableOne.Rd +man/clean_comments.sh +tableone.Rcheck +.*.tar.gz diff --git a/Makefile b/Makefile index 198b384..51df3a8 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,70 @@ -# Makefile for generating R packages. -# 2011 Andrew Redd -# -# Assumes Makefile is in a folder where package contents are in a subfolder pkg. -# Roxygen uses the roxygen2 package, and will run automatically on check and all. +## Makefile for generating R packages. +## original by 2011 Andrew Redd +## https://gist.github.com/halpo/1374344 -PKG_VERSION=$(shell grep -i ^version pkg/DESCRIPTION | cut -d : -d \ -f 2) -PKG_NAME=$(shell grep -i ^package pkg/DESCRIPTION | cut -d : -d \ -f 2) +## Modified by kaz-yos for a different directory structure. +## To be put in the package directory. +## The build and check output files are put in the package directory. +## These files as well as Makefile have to be .Rbuildignore. +## writing rules +## https://www.gnu.org/software/make/manual/html_node/Rules.html#Rules -R_FILES := $(wildcard pkg/R/*.R) -SRC_FILES := $(wildcard pkg/src/*) $(addprefix pkg/src/, $(COPY_SRC)) -PKG_FILES := pkg/DESCRIPTION pkg/NAMESPACE $(R_FILES) $(SRC_FILES) +## Extract the package name and version from the DESCRIPTION file. +PKG_NAME=$(shell grep -i ^package: DESCRIPTION | cut -d : -d \ -f 2) +PKG_VERSION=$(shell grep -i ^version: DESCRIPTION | cut -d : -d \ -f 2) -.PHONY: tarball install check clean build +## Define the package directory as ../pkgName (used by roxygenize()) +PKG_QUOTED="\'../${PKG_NAME}\'" -tarball: $(PKG_NAME)_$(PKG_VERSION).tar.gz -$(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES) - R CMD build pkg +## Define files +R_FILES := $(wildcard R/*.R) +SRC_FILES := $(wildcard src/*) $(addprefix src/, $(COPY_SRC)) +PKG_FILES := DESCRIPTION NAMESPACE NEWS $(R_FILES) $(SRC_FILES) -check: $(PKG_NAME)_$(PKG_VERSION).tar.gz - R CMD check $(PKG_NAME)_$(PKG_VERSION).tar.gz +## .PHONY to allow non-file targets (file targets should not be here) +## https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html +.PHONY: build check install clean + + +### Define targets + +## build depends on the *.tar.gz file, i.e., its own product. +## *.tar.gz file is defined seprately to prevent build execution on every invocation. build: $(PKG_NAME)_$(PKG_VERSION).tar.gz - R CMD INSTALL --build $(PKG_NAME)_$(PKG_VERSION).tar.gz +## (file target) The *.tar.gz file depends on package files including NAMESPACE, +## and build *.tar.gz file from these. +$(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES) + R CMD build ../${PKG_NAME} + +## (file target) NAMESPACE depends on *.R files, and excecute roxygen2 on these. +NAMESPACE: $(R_FILES) + Rscript -e "library(roxygen2); roxygenize(${PKG_QUOTED})" + +## check requires the *.tar.gz file, and execute strict tests on it. +check: $(PKG_NAME)_$(PKG_VERSION).tar.gz + R CMD check --as-cran ./$(PKG_NAME)_$(PKG_VERSION).tar.gz + +## install requires the *.tar.gz file, and execute installation using it. install: $(PKG_NAME)_$(PKG_VERSION).tar.gz - R CMD INSTALL $(PKG_NAME)_$(PKG_VERSION).tar.gz + R CMD install ./$(PKG_NAME)_$(PKG_VERSION).tar.gz -pkg/NAMESPACE: $(R_FILES) - Rscript -e "library(roxygen2);roxygenize('pkg')" +## clean has no dependency, and execute removal of make output files. clean: - -rm -f $(PKG_NAME)_*.tar.gz + -rm -f $(PKG_NAME)_*.tar.gz -rm -r -f $(PKG_NAME).Rcheck - -rm -r -f pkg/man/* - -rm -r -f pkg/NAMESPACE + -rm -r -f man/*.Rd + -rm -r -f NAMESPACE + + +## Define a target "list" that just prints the names of files. .PHONY: list list: @echo "R files:" @echo $(R_FILES) + @echo @echo "Source files:" @echo $(SRC_FILES) From ab2fa858c36960c74a5a017d0e446c1a79d7ac15 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Mar 2014 23:12:26 -0500 Subject: [PATCH 06/12] Makefile simplified (roxygen('.')), compile.sh deleted (obsolete) --- DESCRIPTION | 2 +- Makefile | 6 +----- compile.sh | 39 --------------------------------------- 3 files changed, 2 insertions(+), 45 deletions(-) delete mode 100755 compile.sh diff --git a/DESCRIPTION b/DESCRIPTION index f63245b..8a80ad1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: tableone Type: Package Title: Create "Table 1" to describe baseline characteristics Version: 0.3.4 -Date: 2014-02-28 +Date: 2014-03-01 Author: Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida Description: This package creates "Table 1", i.e., description of baseline diff --git a/Makefile b/Makefile index 51df3a8..1d70903 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,6 @@ PKG_NAME=$(shell grep -i ^package: DESCRIPTION | cut -d : -d \ -f 2) PKG_VERSION=$(shell grep -i ^version: DESCRIPTION | cut -d : -d \ -f 2) -## Define the package directory as ../pkgName (used by roxygenize()) -PKG_QUOTED="\'../${PKG_NAME}\'" - - ## Define files R_FILES := $(wildcard R/*.R) SRC_FILES := $(wildcard src/*) $(addprefix src/, $(COPY_SRC)) @@ -41,7 +37,7 @@ $(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES) ## (file target) NAMESPACE depends on *.R files, and excecute roxygen2 on these. NAMESPACE: $(R_FILES) - Rscript -e "library(roxygen2); roxygenize(${PKG_QUOTED})" + Rscript -e "library(roxygen2); roxygenize('.')" ## check requires the *.tar.gz file, and execute strict tests on it. check: $(PKG_NAME)_$(PKG_VERSION).tar.gz diff --git a/compile.sh b/compile.sh deleted file mode 100755 index 6d032cb..0000000 --- a/compile.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -## Set package name -pkgName="tableone" - -## build documents (load methods and utils explicitly) -echo "################################################################################" -echo "creating .rd files" -# echo "running ./man_create.R" -echo "" -# ./man_create.R -Rscript -e 'library(methods); library(utils); devtools::document("../tableone/"); devtools::check_doc("../tableone/")' - - -## build a package -echo "" -echo "################################################################################" -echo "building" -echo "" -cd ../ -R CMD build ./tableone - -## run tests on the latest archive file -echo "" -echo "################################################################################" -archiveName=`find tableone_*.tar.gz | tail -n 1` -echo "checking ${archiveName}" -echo "" -R CMD check --as-cran ${archiveName} - -## open the test -echo "" -echo "################################################################################" -echo "opening test results" -echo "" -open ./tableone.Rcheck - -## get back to the same directory -cd ./tableone From 0aee030e29081cd1dda4de40aeb832cfdcc3a659 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Mar 2014 23:16:23 -0500 Subject: [PATCH 07/12] man_create.R deleted (obsolete) Use Makefile now --- man_create.R | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100755 man_create.R diff --git a/man_create.R b/man_create.R deleted file mode 100755 index 341f319..0000000 --- a/man_create.R +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/Rscript - -################################################################################ -### .Rd creater -## Creates .Rd from in-source Roxygen2 docs in .R files -## Created on: 2014-02-10 -## Author: Kazuki Yoshida -################################################################################ - -## How to make it work with Rscript (load methods and utils explicitly) -## http://stackoverflow.com/questions/8964515/cannot-call-roxygenize-function-from-rscript-batch-file - -### Prepare environment -################################################################################ - -### Load packages -library(methods) -library(utils) -library(devtools) - - - -### Prepare docs -################################################################################ - -## Create .Rd (clean = TRUE erase non-.Rd files!) -devtools::document("~/Documents/statistics/package_development/tableone/") -## Check -devtools::check_doc("~/Documents/statistics/package_development/tableone/") - From 3419997f6a853855817eb3eceebd12a5d71ac946 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Tue, 4 Mar 2014 18:56:12 -0500 Subject: [PATCH 08/12] strata variable handling. Errors on single-level variables and all NA variables --- R/modules.R | 54 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/R/modules.R b/R/modules.R index 6448f1d..0662d47 100644 --- a/R/modules.R +++ b/R/modules.R @@ -64,23 +64,55 @@ ModuleReturnFalseIfNoStrata <- function(strata, test) { # Give strata variable n ## Check statra variables and conditionally create strata data frame ModuleReturnStrata <- function(strata, data, dat) { # Give strata variable names + ## strata: char vector; data: data frame given; dat = data[c(vars)] 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 { + ## If there is no strata, give "Overall" to every subject (dim1 is nrow) + strata <- rep("Overall", dim(dat)[1]) + + } else { # If strata is given - ## Check presence of strata variables in the data frame (multivariable support) - presenceOfStrata <- strata %in% names(data) - ## Delete variables that do not exist in the data frame - strata <- strata[presenceOfStrata] + ## Drop nonexisting and NA/NaN only variables + strata <- ModuleReturnVarsExist(strata, data) + ## Conditional on presence of remaining variable if (length(strata) == 0) { - stop("None of the stratifying variables are present in the data frame") - } + ## Stop if none left + stop("None of the stratifying variables are present in the data frame.") + + } else { + + ## Check validity of the remaining variables + logiSingleLevelOnly <- + lapply(data[c(strata)], + function(VEC) { + ## Check number of levels + nLevels <- ifelse(test = is.factor(VEC), + yes = nlevels(VEC), + no = nlevels(factor(VEC))) + ## Return logical indicating only one valid level + nLevels == 1 + }) + logiSingleLevelOnly <- unlist(logiSingleLevelOnly) + + ## Only keep variables that have 2+ levels + if (any(logiSingleLevelOnly)) { + warning("These variables have only one valid level: ", + paste0(strata[logiSingleLevelOnly], sep = " "), " Dropped") + + strata <- strata[!logiSingleLevelOnly] + + } + + ## Stop if no variables are left + if (length(strata) == 0) { + ## Stop if none left + stop("None of the stratifying variables have 2+ valid levels.") + } - ## Extract the stratifying variable vector (strata is a data frame) - strata <- data[c(strata)] + ## Extract the stratifying variable vector (strata is a data frame) + strata <- data[c(strata)] + } } ## return DF with strata variable(s) From 28f5ff4c083c4d75c60abe9614f1ad41d78139ec Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Tue, 4 Mar 2014 19:15:19 -0500 Subject: [PATCH 09/12] duplication removal added to strata creation function. --- R/modules.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/modules.R b/R/modules.R index 0662d47..455a655 100644 --- a/R/modules.R +++ b/R/modules.R @@ -23,7 +23,7 @@ ModuleReturnVarsExist <- function(vars, data) { varsNotInData <- setdiff(vars, names(data)) if (length(varsNotInData) > 0) { - warning("The data frame does not have ", + warning("The data frame does not have: ", paste0(varsNotInData, sep = " "), " Dropped") ## Only keep variables that exist vars <- intersect(vars, names(data)) @@ -72,6 +72,9 @@ ModuleReturnStrata <- function(strata, data, dat) { # Give strata variable n } else { # If strata is given + ## unique it first to remove duplications + strata <- unique(strata) + ## Drop nonexisting and NA/NaN only variables strata <- ModuleReturnVarsExist(strata, data) From e4e0d42c4731f59b8dda88b892e7a107f68f90a9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Tue, 4 Mar 2014 19:15:48 -0500 Subject: [PATCH 10/12] strata checking added to CreateTableOne to avoid error messages arising from CreateCatTable and CreateContTable called by CreateTableOne. --- R/CreateTableOne.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 897b885..08d275b 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -148,8 +148,15 @@ CreateTableOne <- argsExact = argsExact ) ## Add strata = strata for argument only if strata is given - if(!missing(strata)) { + if (!missing(strata)) { + ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. + ## Must not be place outside if (!missing(strata)) { }. + dfStrata <- ModuleReturnStrata(strata, data, dat) + ## Return variable names. Code inefficient in exchange for code simplicity. + strata <- names(dfStrata) + + ## Create lists of arguments including strata argsCreateContTable <- c(list(strata = strata), argsCreateContTable) argsCreateCatTable <- c(list(strata = strata), argsCreateCatTable) } From f9cca7177f4f0508ae52465f62aec8c259ab0817 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Tue, 4 Mar 2014 19:45:58 -0500 Subject: [PATCH 11/12] ModuleReturnStrata(strata, data) No dat argument, which was redundant. --- R/CreateCatTable.R | 2 +- R/CreateContTable.R | 2 +- R/CreateTableOne.R | 2 +- R/modules.R | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 1f30163..b0d6bb6 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -110,7 +110,7 @@ CreateCatTable <- dat[datNotFactor] <- lapply(dat[datNotFactor], factor) ## Create strata data frame (data frame with only strata variables) - strata <- ModuleReturnStrata(strata, data, dat) + strata <- ModuleReturnStrata(strata, data) ### Actual descriptive statistics are calculated here. diff --git a/R/CreateContTable.R b/R/CreateContTable.R index 252e44f..d890b4d 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -114,7 +114,7 @@ CreateContTable <- test <- ModuleReturnFalseIfNoStrata(strata, test) ## Create strata data frame (data frame with only strata variables) - strata <- ModuleReturnStrata(strata, data, dat) + strata <- ModuleReturnStrata(strata, data) ## Handle non-numeric elements (intergers give TRUE, and pass) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 08d275b..e170aec 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -152,7 +152,7 @@ CreateTableOne <- ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. ## Must not be place outside if (!missing(strata)) { }. - dfStrata <- ModuleReturnStrata(strata, data, dat) + dfStrata <- ModuleReturnStrata(strata, data) ## Return variable names. Code inefficient in exchange for code simplicity. strata <- names(dfStrata) diff --git a/R/modules.R b/R/modules.R index 455a655..5207167 100644 --- a/R/modules.R +++ b/R/modules.R @@ -63,12 +63,12 @@ ModuleReturnFalseIfNoStrata <- function(strata, test) { # Give strata variable n } ## Check statra variables and conditionally create strata data frame -ModuleReturnStrata <- function(strata, data, dat) { # Give strata variable names - ## strata: char vector; data: data frame given; dat = data[c(vars)] +ModuleReturnStrata <- function(strata, data) { # Give strata variable names + ## strata: char vector; data: data frame given if(missing(strata)) { ## If there is no strata, give "Overall" to every subject (dim1 is nrow) - strata <- rep("Overall", dim(dat)[1]) + strata <- rep("Overall", nrow(data)) } else { # If strata is given From ea3bf4ebccd820328d3b67ff030853f0dfe86eb8 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Tue, 4 Mar 2014 20:02:48 -0500 Subject: [PATCH 12/12] documented change regarding the handling of strata variables. --- DESCRIPTION | 2 +- NEWS | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8a80ad1..beaba14 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: tableone Type: Package Title: Create "Table 1" to describe baseline characteristics Version: 0.3.4 -Date: 2014-03-01 +Date: 2014-03-04 Author: Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida Description: This package creates "Table 1", i.e., description of baseline diff --git a/NEWS b/NEWS index cef8a34..1fc8456 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -tableone 0.3.4 (2014-02-28) +tableone 0.3.4 (2014-03-04) ---------------------------------------------------------------- BUG FIXES @@ -7,6 +7,10 @@ BUG FIXES These invalid variables are examined at the beginning and dropped with warning for safety. +* For the strata argument, variables with only one level is dropped + with warning because these are meaningless, and caused data + handling problems. + tableone 0.3.3 (2014-02-22) ----------------------------------------------------------------