Skip to content

Commit

Permalink
don't use special char
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 20, 2024
1 parent 340b90c commit f18ed1e
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions tests/testthat/test-pretty_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,34 @@ test_that("pretty_names", {
)
})

skip_if_not_installed("withr")

test_that("pretty_labels", {
set.seed(1024)
N <- 5000
X <- rbinom(N, 1, .5)
M <- sample(c("a", "b", "c"), N, replace = TRUE)
b <- runif(8, -1, 1)
Y <- rbinom(N, 1, prob = plogis(
b[1] + b[2] * X +
b[3] * (M == "b") + b[4] * (M == "b") + b[5] * (M == "c") +
b[6] * X * (M == "a") + b[7] * X + (M == "b") +
b[8] * X * (M == "c")
))
dat <- data.frame(Y, X, M, stringsAsFactors = FALSE)
mod <- glm(Y ~ X * M, data = dat, family = binomial)
# make sure we have the correct interaction mark for tests
withr::with_options(
list(parameters_interaction = "*"),
test_that("pretty_labels", {
set.seed(1024)
N <- 5000
X <- rbinom(N, 1, .5)
M <- sample(c("a", "b", "c"), N, replace = TRUE)
b <- runif(8, -1, 1)
Y <- rbinom(N, 1, prob = plogis(
b[1] + b[2] * X +
b[3] * (M == "b") + b[4] * (M == "b") + b[5] * (M == "c") +
b[6] * X * (M == "a") + b[7] * X + (M == "b") +
b[8] * X * (M == "c")
))
dat <- data.frame(Y, X, M, stringsAsFactors = FALSE)
mod <- glm(Y ~ X * M, data = dat, family = binomial)

p <- parameters(mod)
expect_identical(
attr(p, "pretty_labels"),
c(
`(Intercept)` = "(Intercept)", X = "X", Mb = "M [b]", Mc = "M [c]",
`X:Mb` = "X × M [b]", `X:Mc` = "X × M [c]"
p <- parameters(mod)
expect_identical(
attr(p, "pretty_labels"),
c(
`(Intercept)` = "(Intercept)", X = "X", Mb = "M [b]", Mc = "M [c]",
`X:Mb` = "X * M [b]", `X:Mc` = "X * M [c]"
)
)
)
expect_snapshot(print(p))
})
expect_snapshot(print(p))
})
)

0 comments on commit f18ed1e

Please sign in to comment.