diff --git a/DESCRIPTION b/DESCRIPTION index 85a40f2..bddb7f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 Description: Creates "Table 1", i.e., description of baseline patient diff --git a/NEWS b/NEWS index c17a36e..9f0c8d4 100644 --- a/NEWS +++ b/NEWS @@ -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) ---------------------------------------------------------------- diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 72f1673..3901e73 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -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) diff --git a/cran-check.txt b/cran-check.txt index 1c59258..81e7fc7 100644 --- a/cran-check.txt +++ b/cran-check.txt @@ -3,7 +3,7 @@ * 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) @@ -11,7 +11,7 @@ * 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 diff --git a/cran-comment.md b/cran-comment.md index 26e1334..a3b5af0 100644 --- a/cran-comment.md +++ b/cran-comment.md @@ -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 diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index 425fbe4..5f89362 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -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 diff --git a/test-all.txt b/test-all.txt index 39e8abe..01fcb09 100644 --- a/test-all.txt +++ b/test-all.txt @@ -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 @@ -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 =================================================================================================================== diff --git a/tests/testthat/ref-TableOne_print_missing b/tests/testthat/ref-TableOne_print_missing new file mode 100644 index 0000000..3b88e2e Binary files /dev/null and b/tests/testthat/ref-TableOne_print_missing differ diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 193fa56..7184c0c 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -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"]), @@ -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") + }) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index bf2e210..a7d7c8c 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -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"]),