Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 9 additions & 10 deletions R/format_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
} else {
out <- attr(vec, "label", exact = TRUE)
}
if (is.null(out)) {

Check warning on line 403 in R/format_parameters.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format_parameters.R,line=403,col=7,[coalesce_linter] Use x %||% y instead of if (is.null(x)) y else x.
i
} else {
out
Expand All @@ -425,21 +425,20 @@
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)) {
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-pretty_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

withr::with_options(
list(parameters_exponentiate = FALSE, parameters_warning_exponentiate = FALSE),
{

Check warning on line 72 in tests/testthat/test-pretty_names.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-pretty_names.R,line=72,col=3,[unnecessary_nesting_linter] Reduce the nesting of this statement by removing the braces {}.
test_that("pretty_labels, pscl", {
skip_if_not_installed("pscl")

Expand All @@ -80,6 +80,13 @@

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))
})
}
)
Loading