diff --git a/DESCRIPTION b/DESCRIPTION index 307fb42e2..e38b9ad5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.26.0.15 +Version: 0.26.0.16 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/R/format_parameters.R b/R/format_parameters.R index a99e907c1..84a80766b 100644 --- a/R/format_parameters.R +++ b/R/format_parameters.R @@ -425,21 +425,20 @@ format_parameters.parameters_model <- function(model, ...) { unlist(preds, use.names = FALSE) )) - # for models from pscl, we have "count_" and "zero_" prefixes, which - # we need to add to the "pretty_labels" names, so that we can match - # them with the parameters - if (inherits(model, c("zeroinfl", "hurdle"))) { - pretty_labels <- c( - stats::setNames(pretty_labels, paste0("count_", names(pretty_labels))), - stats::setNames(pretty_labels, paste0("zero_", names(pretty_labels))) - ) - } - # retrieve pretty names attribute pn <- attributes(params)$pretty_names # replace former pretty names with labels, if we have any labels # (else, default pretty names are returned) if (!is.null(pretty_labels)) { + # for models from pscl, we have "count_" and "zero_" prefixes, which + # we need to add to the "pretty_labels" names, so that we can match + # them with the parameters + if (inherits(model, c("zeroinfl", "hurdle"))) { + pretty_labels <- c( + stats::setNames(pretty_labels, paste0("count_", names(pretty_labels))), + stats::setNames(pretty_labels, paste0("zero_", names(pretty_labels))) + ) + } # check if we have any interactions, and if so, create combined labels interactions <- pn[grepl(":", names(pn), fixed = TRUE)] if (length(interactions)) { diff --git a/tests/testthat/test-pretty_names.R b/tests/testthat/test-pretty_names.R index 0d584bf99..40da2970b 100644 --- a/tests/testthat/test-pretty_names.R +++ b/tests/testthat/test-pretty_names.R @@ -80,6 +80,13 @@ withr::with_options( model <- pscl::zeroinfl(art ~ fem + mar, data = mydf) expect_snapshot(print(model_parameters(model), pretty_names = "labels", zap_small = TRUE)) + + # doesn't crash if pretty-labels is NULL + mydf <- pscl::bioChemists + mydf$mar <- as.character(mydf$mar) + model <- pscl::zeroinfl(art ~ fem + mar, data = mydf) + out <- model_parameters(model) + expect_identical(dim(out), c(6L, 10L)) }) } )