Skip to content

Commit f18ed1e

Browse files
committed
don't use special char
1 parent 340b90c commit f18ed1e

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

tests/testthat/test-pretty_names.R

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,34 @@ test_that("pretty_names", {
3434
)
3535
})
3636

37+
skip_if_not_installed("withr")
3738

38-
test_that("pretty_labels", {
39-
set.seed(1024)
40-
N <- 5000
41-
X <- rbinom(N, 1, .5)
42-
M <- sample(c("a", "b", "c"), N, replace = TRUE)
43-
b <- runif(8, -1, 1)
44-
Y <- rbinom(N, 1, prob = plogis(
45-
b[1] + b[2] * X +
46-
b[3] * (M == "b") + b[4] * (M == "b") + b[5] * (M == "c") +
47-
b[6] * X * (M == "a") + b[7] * X + (M == "b") +
48-
b[8] * X * (M == "c")
49-
))
50-
dat <- data.frame(Y, X, M, stringsAsFactors = FALSE)
51-
mod <- glm(Y ~ X * M, data = dat, family = binomial)
39+
# make sure we have the correct interaction mark for tests
40+
withr::with_options(
41+
list(parameters_interaction = "*"),
42+
test_that("pretty_labels", {
43+
set.seed(1024)
44+
N <- 5000
45+
X <- rbinom(N, 1, .5)
46+
M <- sample(c("a", "b", "c"), N, replace = TRUE)
47+
b <- runif(8, -1, 1)
48+
Y <- rbinom(N, 1, prob = plogis(
49+
b[1] + b[2] * X +
50+
b[3] * (M == "b") + b[4] * (M == "b") + b[5] * (M == "c") +
51+
b[6] * X * (M == "a") + b[7] * X + (M == "b") +
52+
b[8] * X * (M == "c")
53+
))
54+
dat <- data.frame(Y, X, M, stringsAsFactors = FALSE)
55+
mod <- glm(Y ~ X * M, data = dat, family = binomial)
5256

53-
p <- parameters(mod)
54-
expect_identical(
55-
attr(p, "pretty_labels"),
56-
c(
57-
`(Intercept)` = "(Intercept)", X = "X", Mb = "M [b]", Mc = "M [c]",
58-
`X:Mb` = "X × M [b]", `X:Mc` = "X × M [c]"
57+
p <- parameters(mod)
58+
expect_identical(
59+
attr(p, "pretty_labels"),
60+
c(
61+
`(Intercept)` = "(Intercept)", X = "X", Mb = "M [b]", Mc = "M [c]",
62+
`X:Mb` = "X * M [b]", `X:Mc` = "X * M [c]"
63+
)
5964
)
60-
)
61-
expect_snapshot(print(p))
62-
})
65+
expect_snapshot(print(p))
66+
})
67+
)

0 commit comments

Comments
 (0)