Skip to content

Commit

Permalink
fixed handling of trailing zeros in prettify (closes #40)
Browse files Browse the repository at this point in the history
  • Loading branch information
hofnerb committed Jan 3, 2019
1 parent 193c385 commit d472cf0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 3 additions & 6 deletions R/prettify.R
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ prettify.data.frame <- function(object, labels = NULL, sep = ": ", extra.column
}


### helper for pretty p-values
### helper for pretty p-values and other numerical values
prettifyPValue <- function(object,
smallest.pval = 0.001, digits = NULL, scientific = FALSE,
signif.stars = getOption("show.signif.stars"), ...) {
Expand All @@ -492,11 +492,8 @@ prettifyPValue <- function(object,
}

if (!is.null(digits)) {
for (i in names(object)[-wchPval]) {
if (is.numeric(object[, i]))
object[, i] <- format(zapsmall(object[, i]), digits = digits,
scientific = scientific, ...)
}
object[-wchPval] <- sapply(object[-wchPval], function(col)
formatC(col, digits = digits, flag = "#", ...))
}

object
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-prettify.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,16 @@ if (require("nlme", quietly = TRUE) && require("survival", quietly = TRUE) && re
}
})
}

################################################################################
## Test that trailing zeros are not dropped
################################################################################

if (require("survival", quietly = TRUE)) {
test_that("trailing zeros are not dropped", {
data(ovarian, package = "survival")
mod <- coxph(Surv(futime, fustat) ~ age, data = ovarian)
x <- prettify(summary(mod), digit = 3, env = .GlobalEnv)
expect_match(x[1,5], "1.30")
})
}

0 comments on commit d472cf0

Please sign in to comment.