Skip to content

Commit

Permalink
Merge branch 'hotfix/align-missing' (fix Missing alignment)
Browse files Browse the repository at this point in the history
The demonstrating case in the README.md was a corner case that breaks
alignments between categorical and continuous variables. The following
was used to reproduce the issue.

library(tableone)
library(survival); data(pbc)
vars <- names(pbc)[-1]
tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc,
                            factorVars = c("status","edema","stage"))
print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"),
      exact = c("status","stage"), test = FALSE, smd = TRUE, missing = TRUE)
  • Loading branch information
kaz-yos committed Jun 16, 2017
2 parents a91c08c + 79648ea commit 1de0d1d
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 49 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.8.0
Date: 2017-06-15
Version: 0.8.1
Date: 2017-06-16
Author: Kazuki Yoshida, Justin Bohn.
Maintainer: Kazuki Yoshida <[email protected]>
Description: Creates "Table 1", i.e., description of baseline patient
Expand Down
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
tableone 0.8.1 (2017-06-16)
----------------------------------------------------------------

BUG FIX

* Fix alignment issue with the Missing column. Note currently the
percentage is shown with 1 decimal and this is hard-coded.


tableone 0.8.0 (2017-06-15)
----------------------------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions R/print.TableOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ function(x, # TableOne object
names(dimnames(out)) <- c("", "")
}

## Right-justify Missing column if showing and not removing spaces.
if (missing & !noSpaces) {
out[,"Missing"] <- format(out[,"Missing"], justify = "right")
}

## Center-justify column names if asked and not removing spaces.
if (padColnames & !noSpaces) {
out <- ModuleMidJustifyColnames(mat = out)
Expand Down
4 changes: 2 additions & 2 deletions cran-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building ‘tableone_0.8.0.tar.gz’
* building ‘tableone_0.8.1.tar.gz’
* using log directory ‘/Users/kazuki/Documents/programming/r/tableone/tableone.Rcheck’
* using R version 3.4.0 (2017-04-21)
* using platform: x86_64-apple-darwin15.6.0 (64-bit)
* using session charset: UTF-8
* using option ‘--as-cran’
* checking for file ‘tableone/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘tableone’ version ‘0.8.0
* this is package ‘tableone’ version ‘0.8.1
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
Expand Down
43 changes: 4 additions & 39 deletions cran-comment.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
## What's new
The following changes are included.

tableone 0.8.0 (2017-06-15)
tableone 0.8.1 (2017-06-16)
----------------------------------------------------------------
NEW FEATURES
* The "missing" option for the print methods was implemented. If
TRUE, a column called "Missing" is added as the rightmost column
of the formatted table. This represents percentage of missing
observation in each variable. Please note this is the percentage
with respect to the unweighted raw observations even in weighted
tables.
* The "padColnames" option was added the print.TableOne method. If
TRUE, the column names of the formatted table become space-padded
to center them.

tableone 0.7.6 (2016-07-12)
----------------------------------------------------------------
BUG FIXES
* The explanation for the "factorVars" argument for the functions
CreateTableOne and svyCreateTableOne were changed for clarity.
When factor variables are included in the argument, they are
releveled to exlude empty levels. This was not clearly documented
in the previous documentation. Thanks @eribul.
* svyrep.design objects (survey design objects with replicate weights)
are allowed for the data argument in svyTableOne. This is considered
experimental. Thanks @przemo.

tableone 0.7.5 (2016-04-10)
----------------------------------------------------------------
BUG FIXES
* ShowRegTable() now correctly supports models fit with geepack,
nlme, and lme4.

tableone 0.7.4 (2016-03-31)
----------------------------------------------------------------
NEW FEATURE
* Define SMD := 0 when the numerator is 0 even if the denominator
is also 0. This is more intuitive because a constant compared
across two groups will give an SMD of 0 rather than NaN (0/0).
For example, if two groups being compared both only have one
gender (all female or all male), then SMD for the gender
variable is defined as 0.
BUG FIX
* Fix alignment issue with the Missing column. Note currently the
percentage is shown with 1 decimal and this is hard-coded.

## Test environments
* Local OS X 10.12.5, R 3.4.0
Expand Down
2 changes: 1 addition & 1 deletion tableone.Rcheck/tableone-Ex.Rout
Original file line number Diff line number Diff line change
Expand Up @@ -3316,7 +3316,7 @@ detaching ‘package:survey’, ‘package:survival’, ‘package:Matrix’,
> ###
> options(digits = 7L)
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
Time elapsed: 9.621 0.285 9.982 0.006 0.006
Time elapsed: 7.4 0.285 8.882 0.005 0.005
> grDevices::dev.off()
null device
1
Expand Down
34 changes: 33 additions & 1 deletion test-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ Unit tests for the CreateTableOne function: .......................
2 4 (19.0) 2 (13.3) 31 ( 22.6) 30 ( 21.6)
3 7 (33.3) 5 (33.3) 49 ( 35.8) 59 ( 42.4)
4 8 (38.1) 7 (46.7) 47 ( 34.3) 47 ( 33.8)
. Stratified by trt
1 2 SMD Missing
n 158 154
time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.017 0.0
status (%) 0.054 0.0
0 83 (52.5) 85 ( 55.2)
1 10 ( 6.3) 9 ( 5.8)
2 65 (41.1) 60 ( 39.0)
trt = 2 (%) 0 ( 0.0) 154 (100.0) NaN 25.4
age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.270 0.0
sex = f (%) 137 (86.7) 139 ( 90.3) 0.111 0.0
ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.089 25.4
hepato = 1 (%) 73 (46.2) 87 ( 56.5) 0.207 25.4
spiders = 1 (%) 45 (28.5) 45 ( 29.2) 0.016 25.4
edema (%) 0.058 0.0
0 132 (83.5) 131 ( 85.1)
0.5 16 (10.1) 13 ( 8.4)
1 10 ( 6.3) 10 ( 6.5)
bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.171 0.0
chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.038 32.1
albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.018 0.0
copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] <0.001 25.8
alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.037 25.4
ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.084 25.4
trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.017 32.5
platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.067 2.6
protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.146 0.5
stage (%) 0.246 1.4
1 12 ( 7.6) 4 ( 2.6)
2 35 (22.2) 32 ( 20.8)
3 56 (35.4) 64 ( 41.6)
4 55 (34.8) 54 ( 35.1)
. Stratified by trt
1 2 p test
n 158 154
Expand Down Expand Up @@ -2838,6 +2870,6 @@ C1 NaN NaN 0 0 0
..

Warnings ---------------------------------------------------------------------------------------------------------------
1. svyrep.design is allowed (@test-svyCreateTableOne.R#504) - No sampling weights provided: equal probability assumed
1. svyrep.design is allowed (@test-svyCreateTableOne.R#507) - No sampling weights provided: equal probability assumed

DONE ===================================================================================================================
Binary file added tests/testthat/ref-TableOne_print_missing
Binary file not shown.
22 changes: 20 additions & 2 deletions tests/testthat/test-CreateTableOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ test_that("Missing percentages are correctly stored and printed", {
## Check printing
## Gold standard
percentMissingString <- format(sprintf("%.1f", percentMissing), justify = "right")
## Function to drop empty "" elements.
## Function to drop empty elements like "" or " ".
DropEmptyString <- function(x) {
## as.character() drops names.
as.character(Filter(f = function(elt) {!(elt == "")}, x = x))
as.character(Filter(f = function(elt) {
!grepl("^ *$", elt)
},
x = x))
}
## Check against gold standard
expect_equal(DropEmptyString(print(pbcOverall, missing = TRUE)[,"Missing"]),
Expand All @@ -197,6 +200,21 @@ test_that("Missing percentages are correctly stored and printed", {
expect_equal(DropEmptyString(print(pbcByTrtSex, missing = TRUE)[,"Missing"]),
percentMissingString)

## Regression test for missing column
## This corner case breaks alignment.
data(pbc)
vars <- names(pbc)[-1]
## Create Table 1 stratified by trt (can add more stratifying variables)
tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc,
factorVars = c("status","edema","stage"))
## 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.
expect_equal_to_reference(print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"),
exact = c("status","stage"), test = FALSE, smd = TRUE, missing = TRUE,
printToggle = TRUE),
"ref-TableOne_print_missing")

})


Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-svyCreateTableOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ test_that("Missing percentages are correctly stored and printed", {
## Check printing
## Gold standard
percentMissingString <- format(sprintf("%.1f", percentMissing), justify = "right")
## Function to drop empty "" elements.
## Function to drop empty elements like "" or " ".
DropEmptyString <- function(x) {
## as.character() drops names.
as.character(Filter(f = function(elt) {!(elt == "")}, x = x))
as.character(Filter(f = function(elt) {
!grepl("^ *$", elt)
},
x = x))
}
## Check against gold standard
expect_equal(DropEmptyString(print(mwOverall, missing = TRUE)[,"Missing"]),
Expand Down

0 comments on commit 1de0d1d

Please sign in to comment.