From 0a06a59a1d43e59fa96512819228879277576d94 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 16 Jun 2017 09:54:42 -0400 Subject: [PATCH 1/5] Right-justify Missing column in print.TableOne() --- DESCRIPTION | 4 ++-- NEWS | 9 +++++++++ R/print.TableOne.R | 5 +++++ cran-comment.md | 43 ++++--------------------------------------- 4 files changed, 20 insertions(+), 41 deletions(-) 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-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 From bfeca8735a78d342ad33d9a81706198af636780d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 16 Jun 2017 10:07:34 -0400 Subject: [PATCH 2/5] Add regression test and reference object for Missing alignment --- tests/testthat/ref-TableOne_print_missing | Bin 0 -> 919 bytes tests/testthat/test-CreateTableOne.R | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/testthat/ref-TableOne_print_missing diff --git a/tests/testthat/ref-TableOne_print_missing b/tests/testthat/ref-TableOne_print_missing new file mode 100644 index 0000000000000000000000000000000000000000..d552e8b28b638a3247a5b87f4d978f13ee4d7c77 GIT binary patch literal 919 zcmV;I18DpoiwFP!000001C^G|Z__Xoz_YasHU!=1(BOi6K}w~`@^>5wZd`WQ0d_%} zcF5Lji|9wxWYYNO5zlFo+NrZar6%_C`|x}3XSY8Of*{xp219rb%aT} zDs_q|qn6P}n2O4&hIQkV5vDDL5g0(?6uJd^Y~z*^Rk_v19NY?JSsfxKHMlcb6U>=a zMks^nCgj&&Mu-W8iLmO_i-RF!n03Sws>>x7T`_2LfpsgcX%!8vG>#S4rZrSb9P=k= z1y`Wb4UB*tB&`TFt=-c!YV5QuF6?$nS&J^^PR27f7%c=%3Ts)$m4J4p0Y@1cc4NlG$ z8=|_&y4q4y2ya>u)bBmhbsE{T7T}=gJw#`VTg!q)#F|k`ZErfZHHmWKIMO# zxVAoLnD)fg&&35>+1diemYHhn4PneP_}9x|G>GMd3V67AP#Hljdw56lGFA6e#>`pH{o7)Ecwq0G6xL z<7|}N`C_~-(ns_a-C9A$NpX{vY2nd+cc11-x%8}zi#(gAE1%JRI!)(EPZoRY8{d=D z_&S?q#@#dnhnHvHe_XY}Ztj<}o~2}V{V>lKo_)N(S>}1V^4pyxvtKyBUl#u5QBwGd zIxbh)o!{a(pCx5FOTA|KYT48CedxJqlv6BUo6VS8V^PyJZ0Kr?b{dPp#re19pTl`p t6xrggL+pzh*UHgu=Y~1DC|60D-Dc?&UH?Wv83_NF?_ZW}1G7^L003e}wkrSt literal 0 HcmV?d00001 diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 193fa56..793ba53 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -197,6 +197,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") + }) From fb96aa2a8826ddea0a564bdea1fcc43abb9b849d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 16 Jun 2017 10:15:12 -0400 Subject: [PATCH 3/5] Fix testing of missing % values --- tests/testthat/test-CreateTableOne.R | 7 +++++-- tests/testthat/test-svyCreateTableOne.R | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 793ba53..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"]), 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"]), From f7b4bc9ad6761e2978dfa86b4b39407b23612ad4 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 16 Jun 2017 10:40:03 -0400 Subject: [PATCH 4/5] Add print missing reference object --- test-all.txt | 34 +++++++++++++++++++++- tests/testthat/ref-TableOne_print_missing | Bin 919 -> 937 bytes 2 files changed, 33 insertions(+), 1 deletion(-) 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 index d552e8b28b638a3247a5b87f4d978f13ee4d7c77..3b88e2ecb30287c39e49dfc540aa42640c51121d 100644 GIT binary patch literal 937 zcmV;a16KSWiwFP!000001C>@=OWZ&dj=Hr~sjg_TeJS%&$bt-WO(xL3^`#FAtuF=f zA-YjR_r@lI{qv>gY?94MHo%)9=1aoaN>B>fC6S zKN7jXSp+zqeMMr8JI$}Ulj`DF5(R(C_K8CeyKsUC9yAZS7 z#8J0QMI`%;3Z<6#CRifTGM2_zjx@I~heEr0rQJ}Wb_1$ip$qMTj1YyRJBnKolzxMkWH)QSBNYL03SG^>{(MQa7{H`s>tR*CJ5(?nTd@_&#e&%nHIFtfWfPcncdfe#;(MV!xD=ux&v$H}ry z-b=>GH15fI7uRGGbqy!C=_JK0$0_7_{q6gYo65n--Q#@Ha}-Z*pQh=oqr7)_^Ti@r zcH5oBlV5!CIM2F|p$~b7%aeSWK6G20E+%oFOp;Es#d6*=<2{%$4yVzquCd};leH<; zG^o^68EsV-J69K9t3MAHX_lq4hn7NLmGWFU+HTz_$5;6>&eQue8ME8p3{(Z+AN>9W Lkfd69S_=RG`ccLz literal 919 zcmV;I18DpoiwFP!000001C^G|Z__Xoz_YasHU!=1(BOi6K}w~`@^>5wZd`WQ0d_%} zcF5Lji|9wxWYYNO5zlFo+NrZar6%_C`|x}3XSY8Of*{xp219rb%aT} zDs_q|qn6P}n2O4&hIQkV5vDDL5g0(?6uJd^Y~z*^Rk_v19NY?JSsfxKHMlcb6U>=a zMks^nCgj&&Mu-W8iLmO_i-RF!n03Sws>>x7T`_2LfpsgcX%!8vG>#S4rZrSb9P=k= z1y`Wb4UB*tB&`TFt=-c!YV5QuF6?$nS&J^^PR27f7%c=%3Ts)$m4J4p0Y@1cc4NlG$ z8=|_&y4q4y2ya>u)bBmhbsE{T7T}=gJw#`VTg!q)#F|k`ZErfZHHmWKIMO# zxVAoLnD)fg&&35>+1diemYHhn4PneP_}9x|G>GMd3V67AP#Hljdw56lGFA6e#>`pH{o7)Ecwq0G6xL z<7|}N`C_~-(ns_a-C9A$NpX{vY2nd+cc11-x%8}zi#(gAE1%JRI!)(EPZoRY8{d=D z_&S?q#@#dnhnHvHe_XY}Ztj<}o~2}V{V>lKo_)N(S>}1V^4pyxvtKyBUl#u5QBwGd zIxbh)o!{a(pCx5FOTA|KYT48CedxJqlv6BUo6VS8V^PyJZ0Kr?b{dPp#re19pTl`p t6xrggL+pzh*UHgu=Y~1DC|60D-Dc?&UH?Wv83_NF?_ZW}1G7^L003e}wkrSt From 79648eaa8840b707ac1e6bac9e0aa3a6726ab38c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 16 Jun 2017 10:43:03 -0400 Subject: [PATCH 5/5] Add check results --- cran-check.txt | 4 ++-- tableone.Rcheck/tableone-Ex.Rout | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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/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