Skip to content

Commit

Permalink
bug fix in ggcoef_model when tidy() does not return a p.value (#400)
Browse files Browse the repository at this point in the history
Co-authored-by: Joseph Larmarange <[email protected]>
  • Loading branch information
larmarange authored Mar 7, 2021
1 parent bb51db8 commit 8fd00c1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions R/ggcoef_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ ggcoef_data <- function (
keep_model = FALSE
)

if (!"p.value" %in% names(data)) {
data$p.value <- NA_real_
significance <- NULL
}

if(!is.null(significance)) {
if (is.null(significance_labels))
significance_labels <- paste(c("p \u2264", "p >"), significance)
Expand Down
33 changes: 27 additions & 6 deletions tests/testthat/test-ggcoef_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ test_that("example of ggcoef_model", {

# or with different type of contrasts
# for sum contrasts, the value of the reference term is computed
mod2 <- lm(
tip ~ day + time + sex,
data = tips,
contrasts = list(time = contr.sum, day = contr.treatment(4, base = 3))
)
expect_print(ggcoef_model(mod2))
emmeans_is_installed <- (system.file(package = "emmeans") != "")
if (emmeans_is_installed) {
mod2 <- lm(
tip ~ day + time + sex,
data = tips,
contrasts = list(time = contr.sum, day = contr.treatment(4, base = 3))
)
expect_print(ggcoef_model(mod2))

}

# Use ggcoef_compare() for comparing several models on the same plot
mod1 <- lm(Fertility ~ ., data = swiss)
Expand All @@ -124,3 +128,20 @@ test_that("example of ggcoef_model", {


})

test_that("ggcoef_model works with tieders not returning p-values", {
skip_if_not_installed("broom.helpers")
skip_if_not_installed("scagnostics")

mod <- lm(Sepal.Width ~ Species, iris)
my_tidier <- function(x, ...) {
x %>%
broom::tidy(...) %>%
dplyr::select(-.data$p.value)
}
expect_error(
mod %>% ggcoef_model(tidy_fun = my_tidier),
NA
)

})

0 comments on commit 8fd00c1

Please sign in to comment.