Skip to content

Commit 288542b

Browse files
authored
truncate variable descriptions that are wider than the console (#544)
1 parent bc41b0b commit 288542b

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# infer (development version)
22

3+
* The infer print method now truncates output when descriptions of explanatory
4+
or responses variables exceed the console width (#543).
5+
36
* Added missing commas and addressed formatting issues throughout the vignettes and articles. Backticks for package names were removed and missing parentheses for functions were added (@Joscelinrocha).
47

58
# infer 1.0.7

R/print_methods.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ print.infer <- function(x, ...) {
2828
header[3] <- glue('Null Hypothesis: {attr(x, "null")}', .null = "NULL")
2929
}
3030

31-
cat(glue::glue_collapse(header[header != ""], sep = "\n"))
31+
cat(glue::glue_collapse(
32+
header[header != ""],
33+
width = cli::console_width(),
34+
sep = "\n"
35+
))
3236
cat("\n")
3337

3438
NextMethod()

tests/testthat/_snaps/print.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# print method fits linewidth with many predictors (#543)
2+
3+
Code
4+
specify(mtcars, mpg ~ cyl + disp + hp + drat + wt + qsec)
5+
Output
6+
Response: mpg (numeric)
7+
Explanatory: cyl (numeric), disp (numeric), hp (numer...
8+
# A tibble: 32 x 7
9+
mpg cyl disp hp drat wt qsec
10+
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
11+
1 21 6 160 110 3.9 2.62 16.5
12+
2 21 6 160 110 3.9 2.88 17.0
13+
3 22.8 4 108 93 3.85 2.32 18.6
14+
4 21.4 6 258 110 3.08 3.22 19.4
15+
5 18.7 8 360 175 3.15 3.44 17.0
16+
6 18.1 6 225 105 2.76 3.46 20.2
17+
7 14.3 8 360 245 3.21 3.57 15.8
18+
8 24.4 4 147. 62 3.69 3.19 20
19+
9 22.8 4 141. 95 3.92 3.15 22.9
20+
10 19.2 6 168. 123 3.92 3.44 18.3
21+
# i 22 more rows
22+

tests/testthat/test-print.R

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ test_that("print works", {
66
generate(reps = 10, type = "permute")
77
))
88
})
9+
10+
test_that("print method fits linewidth with many predictors (#543)", {
11+
expect_snapshot(specify(mtcars, mpg ~ cyl + disp + hp + drat + wt + qsec))
12+
})

0 commit comments

Comments
 (0)