Skip to content

Commit

Permalink
Merge branch 'hotfix-ordered-factor' (0.3.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaz-yos committed Mar 8, 2014
2 parents 2bab88c + 1b59d1a commit f618efa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: tableone
Type: Package
Title: Create "Table 1" to describe baseline characteristics
Version: 0.3.4
Date: 2014-03-04
Version: 0.3.5
Date: 2014-03-07
Author: Kazuki Yoshida, Justin Bohn
Maintainer: Kazuki Yoshida <[email protected]>
Description: This package creates "Table 1", i.e., description of baseline
Expand Down
10 changes: 10 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
tableone 0.3.5 (2014-03-07)
----------------------------------------------------------------

BUG FIXES

* Added more robust class assessment in CreateTableOne and
CreateCatTable, which now handles ordered factors correctly.
CreateTableOne also drops Surv object for safety.


tableone 0.3.4 (2014-03-04)
----------------------------------------------------------------

Expand Down
11 changes: 8 additions & 3 deletions R/CreateCatTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
##'
##' ## If you need to show both levels for some 2-level factors, use cramVars
##' print(catTableOverall, cramVars = "hepato")
##'
##'
##' ## Use the showAllLevels argument to see all levels for all variables.
##' print(catTableOverall, showAllLevels = TRUE)
##'
Expand Down Expand Up @@ -106,8 +106,13 @@ CreateCatTable <-

## Convert to a factor if it is not a factor already. (categorical version only)
## Not done on factors, to avoid dropping zero levels.
datNotFactor <- sapply(dat, class) != "factor"
dat[datNotFactor] <- lapply(dat[datNotFactor], factor)
## Probably this cannot handle Surv object??
logiNotFactor <- sapply(dat, function(VEC) {
## Return TRUE if classes for a vector does NOT contain class "factor"
!any(VEC %in% c("factor"))
})

dat[logiNotFactor] <- lapply(dat[logiNotFactor], factor)

## Create strata data frame (data frame with only strata variables)
strata <- ModuleReturnStrata(strata, data)
Expand Down
16 changes: 13 additions & 3 deletions R/CreateTableOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,19 @@ CreateTableOne <-
test <- ModuleReturnFalseIfNoStrata(strata, test)

## Get the classes of the variables
varClasses <- sapply(data[vars], class)
varFactors <- names(varClasses[varClasses == "factor" | varClasses == "logical" | varClasses == "character"])
varNumerics <- names(varClasses[varClasses == "numeric" | varClasses == "integer"])
varClasses <- lapply(data[vars], class)

## Classify as varFactors if any one of these classes are contained
varFactors <-sapply(varClasses, function(VEC) {
any(VEC %in% c("factor", "ordered", "logical", "character"))
})
varFactors <- names(varFactors)[varFactors]

## Classify as varNumerics if any one of these classes are contained
varNumerics <-sapply(varClasses, function(VEC) {
any(VEC %in% c("numeric", "integer"))
})
varNumerics <- names(varNumerics)[varNumerics]

## Drop variables that do not meet either because it is unsupported
varDrop <- setdiff(vars, c(varFactors, varNumerics))
Expand Down

0 comments on commit f618efa

Please sign in to comment.