Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading names using pretty_names in combination with cut() #945

Merged
merged 4 commits into from
Feb 7, 2024
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
4 changes: 2 additions & 2 deletions R/format_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

# save some time, if model info is passed as argument
dot_args <- list(...)
if (!is.null(dot_args$model_info)) {

Check warning on line 75 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=75,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
info <- dot_args$model_info
} else {
info <- insight::model_info(model, verbose = FALSE)
Expand Down Expand Up @@ -271,9 +271,9 @@
is_simple = FALSE,
interaction_mark = NULL,
...) {
# sep <- ifelse(is_nested | is_simple, " : ", " * ")

Check warning on line 274 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=274,col=5,[commented_code_linter] Remove commented code.
# sep <- ifelse(is_nested, " / ", " * ")

Check warning on line 275 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=275,col=5,[commented_code_linter] Remove commented code.
# sep <- ifelse(is_simple, " : ", ifelse(is_nested, " / ", " * "))

Check warning on line 276 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=276,col=5,[commented_code_linter] Remove commented code.
if (is.null(interaction_mark)) {
if (.unicode_symbols()) {
sep <- "\u00D7"
Expand Down Expand Up @@ -319,11 +319,11 @@
if (all(grepl(pattern_cut_right, level))) {
lower_bounds <- gsub(pattern_cut_right, "\\1", level)
upper_bounds <- gsub(pattern_cut_right, "\\2", level)
level <- paste0(as.numeric(lower_bounds) + 1, "-", upper_bounds)
level <- paste0(">", as.numeric(lower_bounds), "-", upper_bounds)
} else if (all(grepl(pattern_cut_left, level))) {
lower_bounds <- gsub(pattern_cut_left, "\\1", level)
upper_bounds <- gsub(pattern_cut_left, "\\2", level)
level <- paste0(lower_bounds, "-", as.numeric(upper_bounds) - 1)
level <- paste0(lower_bounds, "-<", as.numeric(upper_bounds))

Check warning on line 326 in R/format_parameters.R

View check run for this annotation

Codecov / codecov/patch

R/format_parameters.R#L326

Added line #L326 was not covered by tests
}
paste0(variable, " ", brackets[1], level, brackets[2])
}
Expand Down Expand Up @@ -453,7 +453,7 @@
win_os <- tryCatch(
{
si <- Sys.info()
if (!is.null(si["sysname"])) {

Check warning on line 456 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=456,col=11,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
si["sysname"] == "Windows" || startsWith(R.version$os, "mingw")
} else {
FALSE
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-format_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,20 @@ withr::with_options(
"e42dep [2] * c12hour"
)
})

test_that("format_parameters, cut", {
data(mtcars)
mtcars$grp <- cut(mtcars$mpg, breaks = c(0, 15, 20, 50))
out <- model_parameters(lm(wt ~ grp, data = mtcars))
expect_equal(
attributes(out)$pretty_names,
c(
`(Intercept)` = "(Intercept)", `grp(15,20]` = "grp [>15-20]",
`grp(20,50]` = "grp [>20-50]"
),
ignore_attr = TRUE
)
expect_identical(out$Parameter, c("(Intercept)", "grp(15,20]", "grp(20,50]"))
})
}
)
Loading