Skip to content

Commit 48a2a4b

Browse files
authored
Merge branch 'main' into strengejacke/issue1034
2 parents c4323aa + 6533602 commit 48a2a4b

File tree

8 files changed

+103
-32
lines changed

8 files changed

+103
-32
lines changed

tests/testthat/_snaps/printing2.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@
141141
-------------------------------------------------------------------------------------------
142142
Observations | 150 | | 150 |
143143

144+
---
145+
146+
Code
147+
print(out, groups = list(Species = c("Species [versicolor]",
148+
"Species [virginica]"), Interactions = c(
149+
"Species [versicolor] * Petal Length", "Species [virginica] * Petal Length"),
150+
Controls = "Petal Length"), select = "{estimate}|{p}")
151+
Output
152+
Parameter | Estimate (lm1) | p (lm1)
153+
----------------------------------------------------------------
154+
Species | |
155+
Species [versicolor] | -1.60 | <0.001
156+
Species [virginica] | -2.12 | <0.001
157+
Interactions | |
158+
Species [versicolor] * Petal Length | |
159+
Species [virginica] * Petal Length | |
160+
Controls | |
161+
Petal Length | 0.90 | <0.001
162+
----------------------------------------------------------------
163+
Observations | 150 |
164+
165+
Parameter | Estimate (lm2) | p (lm2)
166+
----------------------------------------------------------------
167+
Species | |
168+
Species [versicolor] | -1.69 | 0.003
169+
Species [virginica] | -1.19 | 0.048
170+
Interactions | |
171+
Species [versicolor] * Petal Length | -0.01 | 0.961
172+
Species [virginica] * Petal Length | -0.15 | 0.574
173+
Controls | |
174+
Petal Length | 0.39 | 0.138
175+
----------------------------------------------------------------
176+
Observations | 150 |
177+
144178
# combination of different models
145179

146180
Code

tests/testthat/test-compare_parameters.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ skip_if_not_installed("withr")
22

33
# make sure we have the correct interaction mark for tests
44
withr::with_options(
5-
list(parameters_interaction = "*"),
5+
list(parameters_interaction = "*", easystats_table_width = Inf),
66
{
77
data(iris)
88
m1 <- lm(Sepal.Length ~ Species, data = iris)

tests/testthat/test-format_parameters.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ skip_if_not_installed("splines")
22

33
# make sure we have the correct interaction mark for tests
44
withr::with_options(
5-
list(parameters_interaction = "*"),
5+
list(parameters_interaction = "*", easystats_table_width = Inf),
66
{
77
# define here because messes up the expected output
88
bs <- splines::bs

tests/testthat/test-pipe.R

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ test_that("print in pipe", {
1414
)
1515
})
1616

17-
test_that("print in pipe, on-the-fly factor", {
18-
data(mtcars)
19-
out <- capture.output({
20-
mtcars |>
21-
lm(mpg ~ cut(wt, c(0, 2.5, 3, 5)), data = _) |>
22-
model_parameters(include_reference = TRUE)
17+
18+
skip_if_not_installed("withr")
19+
withr::with_options(
20+
list(easystats_table_width = Inf),
21+
test_that("print in pipe, on-the-fly factor", {
22+
data(mtcars)
23+
out <- capture.output({
24+
mtcars |>
25+
lm(mpg ~ cut(wt, c(0, 2.5, 3, 5)), data = _) |>
26+
model_parameters(include_reference = TRUE)
27+
})
28+
expect_identical(
29+
out[4],
30+
"cut(wt, c(0, 2.5, 3, 5)) [>0-2.5] | 0.00 | | | | "
31+
)
2332
})
24-
expect_identical(
25-
out[4],
26-
"cut(wt, c(0, 2.5, 3, 5)) [>0-2.5] | 0.00 | | | | "
27-
)
28-
})
33+
)
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
skip_if_not_installed("AER")
22
skip_if_not_installed("datawizard")
3+
skip_if_not_installed("withr")
34

4-
test_that("templates", {
5-
data(efc, package = "datawizard")
6-
model <- AER::tobit(neg_c_7 ~ e42dep + c172code, data = efc)
7-
mp <- model_parameters(model)
8-
expect_snapshot(print(mp, pretty_names = "labels"))
9-
})
5+
withr::with_options(
6+
list(easystats_table_width = Inf),
7+
test_that("templates", {
8+
data(efc, package = "datawizard")
9+
model <- AER::tobit(neg_c_7 ~ e42dep + c172code, data = efc)
10+
mp <- model_parameters(model)
11+
expect_snapshot(print(mp, pretty_names = "labels"))
12+
})
13+
)

tests/testthat/test-printing.R

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ skip_if_not_installed("withr")
33
skip_if(getRversion() < "4.0.0")
44

55
withr::with_options(
6-
list(parameters_interaction = "*"),
6+
list(parameters_interaction = "*", easystats_table_width = Inf),
77
{
88
# Splitting model components ----
99
test_that("print model with multiple components", {
@@ -111,12 +111,10 @@ withr::with_options(
111111

112112
withr::with_options(
113113
list(parameters_warning_exponentiate = TRUE),
114-
{
115-
test_that("no more message about interpretation of log-resoponse", {
116-
data(mtcars)
117-
m <- lm(log(mpg) ~ gear, data = mtcars)
118-
out <- model_parameters(m, exponentiate = TRUE)
119-
expect_snapshot(print(out))
120-
})
121-
}
114+
test_that("no more message about interpretation of log-resoponse", {
115+
data(mtcars)
116+
m <- lm(log(mpg) ~ gear, data = mtcars)
117+
out <- model_parameters(m, exponentiate = TRUE)
118+
expect_snapshot(print(out))
119+
})
122120
)

tests/testthat/test-printing2.R

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ skip_if_not_installed("withr")
22
skip_if(getRversion() < "4.0.0")
33

44
withr::with_options(
5-
list(parameters_interaction = "*"),
5+
list(parameters_interaction = "*", easystats_table_width = Inf),
66
{
77
lm1 <- lm(Sepal.Length ~ Species, data = iris)
88
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
@@ -66,7 +66,7 @@ withr::with_options(
6666
"Species [virginica]"
6767
),
6868
Interactions = c(
69-
"Species [versicolor] * Petal Length", # note the unicode char!
69+
"Species [versicolor] * Petal Length",
7070
"Species [virginica] * Petal Length"
7171
),
7272
Controls = "Petal Length"
@@ -79,7 +79,7 @@ withr::with_options(
7979
"Species [virginica]"
8080
),
8181
Interactions = c(
82-
"Species [versicolor] * Petal Length", # note the unicode char!
82+
"Species [versicolor] * Petal Length",
8383
"Species [virginica] * Petal Length"
8484
),
8585
Controls = "Petal Length"
@@ -112,3 +112,31 @@ withr::with_options(
112112
})
113113
}
114114
)
115+
116+
117+
withr::with_options(
118+
list(parameters_interaction = "*"),
119+
{
120+
lm1 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
121+
lm2 <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)
122+
123+
# remove intercept
124+
out <- compare_parameters(lm1, lm2, drop = "^\\(Intercept")
125+
126+
test_that("templates, glue-3, separate columnns", {
127+
expect_snapshot(
128+
print(out, groups = list(
129+
Species = c(
130+
"Species [versicolor]",
131+
"Species [virginica]"
132+
),
133+
Interactions = c(
134+
"Species [versicolor] * Petal Length",
135+
"Species [virginica] * Petal Length"
136+
),
137+
Controls = "Petal Length"
138+
), select = "{estimate}|{p}")
139+
)
140+
})
141+
}
142+
)

vignettes/model_parameters_print.Rmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ Redundant columns are removed. The related model component is shown as table hea
119119

120120
```{r eval=successfully_loaded["glmmTMB"]}
121121
mp <- model_parameters(model)
122-
print(mp, split_component = FALSE)
122+
# We use `table_width` here to print a wider table,
123+
# which is not split into multiple tables
124+
print(mp, split_component = FALSE, table_width = Inf)
123125
```
124126

125127
## Adding model information

0 commit comments

Comments
 (0)