Debian Codegraph @

tests/testthat/_snaps/tbl-format.md

raw symbols SCIP
1 # format() reacts on cli.num_colors option
2
3 Code
4 format(as_tbl(trees))
5 Output
6 [1] "\033[90m# A data frame: 31 x 3\033[39m"
7 [2] " Girth Height Volume"
8 [3] " \033[3m\033[90m<dbl>\033[39m\033[23m \033[3m\033[90m<dbl>\033[39m\033[23m \033[3m\033[90m<dbl>\033[39m\033[23m"
9 [4] "\033[90m 1\033[39m 8.3 70 10.3"
10 [5] "\033[90m 2\033[39m 8.6 65 10.3"
11 [6] "\033[90m 3\033[39m 8.8 63 10.2"
12 [7] "\033[90m 4\033[39m 10.5 72 16.4"
13 [8] "\033[90m 5\033[39m 10.7 81 18.8"
14 [9] "\033[90m 6\033[39m 10.8 83 19.7"
15 [10] "\033[90m 7\033[39m 11 66 15.6"
16 [11] "\033[90m 8\033[39m 11 75 18.2"
17 [12] "\033[90m 9\033[39m 11.1 80 22.6"
18 [13] "\033[90m10\033[39m 11.2 75 19.9"
19 [14] "\033[90m# i 21 more rows\033[39m"
20 Code
21 options(cli.num_colors = 1)
22 format(as_tbl(trees))
23 Output
24 [1] "# A data frame: 31 x 3" " Girth Height Volume" " <dbl> <dbl> <dbl>"
25 [4] " 1 8.3 70 10.3" " 2 8.6 65 10.3" " 3 8.8 63 10.2"
26 [7] " 4 10.5 72 16.4" " 5 10.7 81 18.8" " 6 10.8 83 19.7"
27 [10] " 7 11 66 15.6" " 8 11 75 18.2" " 9 11.1 80 22.6"
28 [13] "10 11.2 75 19.9" "# i 21 more rows"
29
30 # print() output
31
32 Code
33 as_tbl(mtcars)
34 Output
35 # A data frame: 32 x 11
36 mpg cyl disp hp drat wt qsec vs am gear carb
37 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
38 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
39 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
40 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
41 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
42 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
43 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
44 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
45 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
46 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
47 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
48 # i 22 more rows
49 Code
50 print(as_tbl(mtcars), n = 8, width = 30)
51 Output
52 # A data frame: 32 x 11
53 mpg cyl disp hp
54 * <dbl> <dbl> <dbl> <dbl>
55 1 21 6 160 110
56 2 21 6 160 110
57 3 22.8 4 108 93
58 4 21.4 6 258 110
59 5 18.7 8 360 175
60 6 18.1 6 225 105
61 7 14.3 8 360 245
62 8 24.4 4 147. 62
63 # i 24 more rows
64 # i 7 more variables:
65 # drat <dbl>, wt <dbl>,
66 # qsec <dbl>, vs <dbl>,
67 # am <dbl>, gear <dbl>,
68 # carb <dbl>
69 Code
70 print(as_tbl(mtcars), n = 30)
71 Output
72 # A data frame: 32 x 11
73 mpg cyl disp hp drat wt qsec vs am gear carb
74 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
75 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
76 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
77 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
78 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
79 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
80 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
81 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
82 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
83 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
84 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
85 11 17.8 6 168. 123 3.92 3.44 18.9 1 0 4 4
86 12 16.4 8 276. 180 3.07 4.07 17.4 0 0 3 3
87 13 17.3 8 276. 180 3.07 3.73 17.6 0 0 3 3
88 14 15.2 8 276. 180 3.07 3.78 18 0 0 3 3
89 15 10.4 8 472 205 2.93 5.25 18.0 0 0 3 4
90 16 10.4 8 460 215 3 5.42 17.8 0 0 3 4
91 17 14.7 8 440 230 3.23 5.34 17.4 0 0 3 4
92 18 32.4 4 78.7 66 4.08 2.2 19.5 1 1 4 1
93 19 30.4 4 75.7 52 4.93 1.62 18.5 1 1 4 2
94 20 33.9 4 71.1 65 4.22 1.84 19.9 1 1 4 1
95 21 21.5 4 120. 97 3.7 2.46 20.0 1 0 3 1
96 22 15.5 8 318 150 2.76 3.52 16.9 0 0 3 2
97 23 15.2 8 304 150 3.15 3.44 17.3 0 0 3 2
98 24 13.3 8 350 245 3.73 3.84 15.4 0 0 3 4
99 25 19.2 8 400 175 3.08 3.84 17.0 0 0 3 2
100 26 27.3 4 79 66 4.08 1.94 18.9 1 1 4 1
101 27 26 4 120. 91 4.43 2.14 16.7 0 1 5 2
102 28 30.4 4 95.1 113 3.77 1.51 16.9 1 1 5 2
103 29 15.8 8 351 264 4.22 3.17 14.5 0 1 5 4
104 30 19.7 6 145 175 3.62 2.77 15.5 0 1 5 6
105 # i 2 more rows
106 Code
107 print(as_tbl(mtcars), n = 100)
108 Output
109 # A data frame: 32 x 11
110 mpg cyl disp hp drat wt qsec vs am gear carb
111 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
112 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
113 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
114 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
115 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
116 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
117 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
118 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
119 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
120 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
121 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
122 11 17.8 6 168. 123 3.92 3.44 18.9 1 0 4 4
123 12 16.4 8 276. 180 3.07 4.07 17.4 0 0 3 3
124 13 17.3 8 276. 180 3.07 3.73 17.6 0 0 3 3
125 14 15.2 8 276. 180 3.07 3.78 18 0 0 3 3
126 15 10.4 8 472 205 2.93 5.25 18.0 0 0 3 4
127 16 10.4 8 460 215 3 5.42 17.8 0 0 3 4
128 17 14.7 8 440 230 3.23 5.34 17.4 0 0 3 4
129 18 32.4 4 78.7 66 4.08 2.2 19.5 1 1 4 1
130 19 30.4 4 75.7 52 4.93 1.62 18.5 1 1 4 2
131 20 33.9 4 71.1 65 4.22 1.84 19.9 1 1 4 1
132 21 21.5 4 120. 97 3.7 2.46 20.0 1 0 3 1
133 22 15.5 8 318 150 2.76 3.52 16.9 0 0 3 2
134 23 15.2 8 304 150 3.15 3.44 17.3 0 0 3 2
135 24 13.3 8 350 245 3.73 3.84 15.4 0 0 3 4
136 25 19.2 8 400 175 3.08 3.84 17.0 0 0 3 2
137 26 27.3 4 79 66 4.08 1.94 18.9 1 1 4 1
138 27 26 4 120. 91 4.43 2.14 16.7 0 1 5 2
139 28 30.4 4 95.1 113 3.77 1.51 16.9 1 1 5 2
140 29 15.8 8 351 264 4.22 3.17 14.5 0 1 5 4
141 30 19.7 6 145 175 3.62 2.77 15.5 0 1 5 6
142 31 15 8 301 335 3.54 3.57 14.6 0 1 5 8
143 32 21.4 4 121 109 4.11 2.78 18.6 1 1 4 2
144 Code
145 print(as_tbl(mtcars), width = 40, max_extra_cols = 1)
146 Output
147 # A data frame: 32 x 11
148 mpg cyl disp hp drat wt
149 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
150 1 21 6 160 110 3.9 2.62
151 2 21 6 160 110 3.9 2.88
152 3 22.8 4 108 93 3.85 2.32
153 4 21.4 6 258 110 3.08 3.22
154 5 18.7 8 360 175 3.15 3.44
155 6 18.1 6 225 105 2.76 3.46
156 7 14.3 8 360 245 3.21 3.57
157 8 24.4 4 147. 62 3.69 3.19
158 9 22.8 4 141. 95 3.92 3.15
159 10 19.2 6 168. 123 3.92 3.44
160 # i 22 more rows
161 # i 5 more variables: qsec <dbl>, ...
162 Code
163 print(as_tbl(mtcars), width = 30, max_footer_lines = 3)
164 Output
165 # A data frame: 32 x 11
166 mpg cyl disp hp
167 * <dbl> <dbl> <dbl> <dbl>
168 1 21 6 160 110
169 2 21 6 160 110
170 3 22.8 4 108 93
171 4 21.4 6 258 110
172 5 18.7 8 360 175
173 6 18.1 6 225 105
174 7 14.3 8 360 245
175 8 24.4 4 147. 62
176 9 22.8 4 141. 95
177 10 19.2 6 168. 123
178 # i 22 more rows
179 # i 7 more variables:
180 # drat <dbl>, wt <dbl>, ...
181 Code
182 rlang::with_options(tibble.print_min = 5, as_tbl(mtcars))
183 Output
184 # A data frame: 32 x 11
185 mpg cyl disp hp drat wt qsec vs am gear carb
186 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
187 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
188 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
189 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
190 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
191 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
192 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
193 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
194 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
195 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
196 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
197 # i 22 more rows
198 Code
199 rlang::with_options(tibble.print_max = 50, as_tbl(mtcars))
200 Output
201 # A data frame: 32 x 11
202 mpg cyl disp hp drat wt qsec vs am gear carb
203 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
204 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
205 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
206 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
207 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
208 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
209 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
210 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
211 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
212 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
213 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
214 # i 22 more rows
215 Code
216 rlang::with_options(tibble.width = 30, as_tbl(mtcars))
217 Output
218 # A data frame: 32 x 11
219 mpg cyl disp hp drat wt qsec vs am gear carb
220 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
221 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
222 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
223 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
224 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
225 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
226 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
227 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
228 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
229 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
230 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
231 # i 22 more rows
232
233 ---
234
235 Code
236 print(as_tbl(mtcars), width = 40, max_extra_cols = 1)
237 Output
238 # A data frame: 32 x 11
239 mpg cyl disp hp drat wt
240 * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
241 1 21 6 160 110 3.9 2.62
242 2 21 6 160 110 3.9 2.88
243 3 22.8 4 108 93 3.85 2.32
244 4 21.4 6 258 110 3.08 3.22
245 5 18.7 8 360 175 3.15 3.44
246 6 18.1 6 225 105 2.76 3.46
247 7 14.3 8 360 245 3.21 3.57
248 8 24.4 4 147. 62 3.69 3.19
249 9 22.8 4 141. 95 3.92 3.15
250 10 19.2 6 168. 123 3.92 3.44
251 # i 22 more rows
252 # i 5 more variables: qsec <dbl>, ...
253 Code
254 print(tbl_format_setup(new_tbl(trees, pillar_focus = "Volume"), width = 30))
255 Output
256 <pillar_tbl_format_setup>
257 <tbl_format_header(setup)>
258 # A data frame: 31 x 3
259 # Focus columns: Volume
260 <tbl_format_body(setup)>
261 Girth Height Volume
262 <dbl> <dbl> <dbl>
263 1 8.3 70 10.3
264 2 8.6 65 10.3
265 3 8.8 63 10.2
266 4 10.5 72 16.4
267 5 10.7 81 18.8
268 6 10.8 83 19.7
269 7 11 66 15.6
270 8 11 75 18.2
271 9 11.1 80 22.6
272 10 11.2 75 19.9
273 <tbl_format_footer(setup)>
274 # i 21 more rows
275
276 # print() and format() can pass down arguments in `...`
277
278 Code
279 format(tbl, known_arg = TRUE)
280 Output
281 [1] "# A data frame: 31 x 3" "# Attribute: Set" " Girth Height Volume"
282 [4] " <dbl> <dbl> <dbl>" " 1 8.3 70 10.3" " 2 8.6 65 10.3"
283 [7] " 3 8.8 63 10.2" " 4 10.5 72 16.4" " 5 10.7 81 18.8"
284 [10] " 6 10.8 83 19.7" " 7 11 66 15.6" " 8 11 75 18.2"
285 [13] " 9 11.1 80 22.6" "10 11.2 75 19.9" "# i 21 more rows"
286 Code
287 print(tbl, known_arg = TRUE)
288 Output
289 # A data frame: 31 x 3
290 # Attribute: Set
291 Girth Height Volume
292 <dbl> <dbl> <dbl>
293 1 8.3 70 10.3
294 2 8.6 65 10.3
295 3 8.8 63 10.2
296 4 10.5 72 16.4
297 5 10.7 81 18.8
298 6 10.8 83 19.7
299 7 11 66 15.6
300 8 11 75 18.2
301 9 11.1 80 22.6
302 10 11.2 75 19.9
303 # i 21 more rows
304 Code
305 print(tbl, known_arg = FALSE)
306 Output
307 # A data frame: 31 x 3
308 Girth Height Volume
309 <dbl> <dbl> <dbl>
310 1 8.3 70 10.3
311 2 8.6 65 10.3
312 3 8.8 63 10.2
313 4 10.5 72 16.4
314 5 10.7 81 18.8
315 6 10.8 83 19.7
316 7 11 66 15.6
317 8 11 75 18.2
318 9 11.1 80 22.6
319 10 11.2 75 19.9
320 # i 21 more rows
321