Debian Codegraph @

tests/testthat/_snaps/num.md

raw symbols SCIP
1 # output test
2
3 Code
4 tibble::tibble(x0 = num(9:11 * 100 + 0.5, sigfig = 3), x1 = num(9:11 * 100 +
5 0.5, sigfig = 4), x2 = num(9:11 * 100 + 0.5, sigfig = 5), )
6 Output
7 # A tibble: 3 x 3
8 x0 x1 x2
9 <num:3> <num:4> <num:5>
10 1 900. 900.5 900.5
11 2 1000. 1000. 1000.5
12 3 1100. 1100. 1100.5
13 Code
14 tibble::tibble(x3 = num(9:11 * 100 + 0.5, digits = 0), x4 = num(9:11 * 100 +
15 0.5, digits = -1), x5 = num(9:11 * 100 + 0.5, digits = -2), )
16 Output
17 # A tibble: 3 x 3
18 x3 x4 x5
19 <num:.0> <num:.1> <num:.2>
20 1 900. 900.5 900.5
21 2 1000. 1000.5 1000.5
22 3 1100. 1100.5 1100.5
23 Code
24 tibble::tibble(usd = num(9:11 * 100 + 0.5, digits = 2, label = "USD"), gbp = num(
25 9:11 * 100 + 0.5, digits = 2, label = "£"), chf = num(9:11 * 100 + 0.5,
26 digits = 2, label = "SFr"))
27 Output
28 # A tibble: 3 x 3
29 usd gbp chf
30 USD £ SFr
31 1 900.50 900.50 900.50
32 2 1000.50 1000.50 1000.50
33 3 1100.50 1100.50 1100.50
34 Code
35 tibble::tibble(small = num(9:11 / 1000 + 5e-05, label = "%", scale = 100),
36 medium = num(9:11 / 100 + 5e-04, label = "%", scale = 100), large = num(9:11 /
37 10 + 0.005, label = "%", scale = 100))
38 Output
39 # A tibble: 3 x 3
40 small medium large
41 % % %
42 1 0.905 9.05 90.5
43 2 1.00 10.0 100.
44 3 1.10 11.0 110.
45 Code
46 tibble::tibble(sci = num(10^(-13:6), notation = "sci"), eng = num(10^(-13:6),
47 notation = "eng"), dec = num(10^(-13:6), notation = "dec"), si = num(10^(-13:6),
48 notation = "si"), )
49 Output
50 # A tibble: 20 x 4
51 sci eng dec si
52 <sci> <eng> <dec> <si>
53 1 1e-13 100e-15 0.0000000000001 100f
54 2 1e-12 1e-12 0.000000000001 1p
55 3 1e-11 10e-12 0.00000000001 10p
56 4 1e-10 100e-12 0.0000000001 100p
57 5 1e- 9 1e- 9 0.000000001 1n
58 6 1e- 8 10e- 9 0.00000001 10n
59 7 1e- 7 100e- 9 0.0000001 100n
60 8 1e- 6 1e- 6 0.000001 1µ
61 9 1e- 5 10e- 6 0.00001 10µ
62 10 1e- 4 100e- 6 0.0001 100µ
63 11 1e- 3 1e- 3 0.001 1m
64 12 1e- 2 10e- 3 0.01 10m
65 13 1e- 1 100e- 3 0.1 100m
66 14 1e+ 0 1e+ 0 1 1
67 15 1e+ 1 10e+ 0 10 10
68 16 1e+ 2 100e+ 0 100 100
69 17 1e+ 3 1e+ 3 1000 1k
70 18 1e+ 4 10e+ 3 10000 10k
71 19 1e+ 5 100e+ 3 100000 100k
72 20 1e+ 6 1e+ 6 1000000 1M
73 Code
74 tibble::tibble(scimin = num(10^(-7:6) * 123, notation = "sci", fixed_exponent = -
75 Inf), engmin = num(10^(-7:6) * 123, notation = "eng", fixed_exponent = -Inf),
76 simin = num(10^(-7:6) * 123, notation = "si", fixed_exponent = -Inf))
77 Output
78 # A tibble: 14 x 3
79 scimin engmin simin
80 [e-5] [e-5] [µ]
81 1 1.23 12.3 12.3
82 2 12.3 123 123
83 3 123 1230 1230
84 4 1230 12300 12300
85 5 12300 123000 123000
86 6 123000 1230000 1230000
87 7 1230000 12300000 12300000
88 8 12300000 123000000 123000000
89 9 123000000 1230000000 1230000000
90 10 1230000000 12300000000 12300000000
91 11 12300000000 123000000000 123000000000
92 12 123000000000 1230000000000 1230000000000
93 13 1230000000000 12300000000000 12300000000000
94 14 12300000000000 123000000000000 123000000000000
95 Code
96 tibble::tibble(scismall = num(10^(-7:6) * 123, notation = "sci",
97 fixed_exponent = -3), engsmall = num(10^(-7:6) * 123, notation = "eng",
98 fixed_exponent = -3), sismall = num(10^(-7:6) * 123, notation = "si",
99 fixed_exponent = -3))
100 Output
101 # A tibble: 14 x 3
102 scismall engsmall sismall
103 [e-3] [e-3] [m]
104 1 0.0123 0.0123 0.0123
105 2 0.123 0.123 0.123
106 3 1.23 1.23 1.23
107 4 12.3 12.3 12.3
108 5 123 123 123
109 6 1230 1230 1230
110 7 12300 12300 12300
111 8 123000 123000 123000
112 9 1230000 1230000 1230000
113 10 12300000 12300000 12300000
114 11 123000000 123000000 123000000
115 12 1230000000 1230000000 1230000000
116 13 12300000000 12300000000 12300000000
117 14 123000000000 123000000000 123000000000
118 Code
119 tibble::tibble(scilarge = num(10^(-7:6) * 123, notation = "sci",
120 fixed_exponent = 3), englarge = num(10^(-7:6) * 123, notation = "eng",
121 fixed_exponent = 3), silarge = num(10^(-7:6) * 123, notation = "si",
122 fixed_exponent = 3))
123 Output
124 # A tibble: 14 x 3
125 scilarge englarge silarge
126 [e3] [e3] [k]
127 1 0.0000000123 0.0000000123 0.0000000123
128 2 0.000000123 0.000000123 0.000000123
129 3 0.00000123 0.00000123 0.00000123
130 4 0.0000123 0.0000123 0.0000123
131 5 0.000123 0.000123 0.000123
132 6 0.00123 0.00123 0.00123
133 7 0.0123 0.0123 0.0123
134 8 0.123 0.123 0.123
135 9 1.23 1.23 1.23
136 10 12.3 12.3 12.3
137 11 123 123 123
138 12 1230 1230 1230
139 13 12300 12300 12300
140 14 123000 123000 123000
141 Code
142 tibble::tibble(scimax = num(10^(-7:6) * 123, notation = "sci", fixed_exponent = Inf),
143 engmax = num(10^(-7:6) * 123, notation = "eng", fixed_exponent = Inf), simax = num(
144 10^(-7:6) * 123, notation = "si", fixed_exponent = Inf))
145 Output
146 # A tibble: 14 x 3
147 scimax engmax simax
148 [e8] [e8] [M]
149 1 0.000000000000123 0.0000000000123 0.0000000000123
150 2 0.00000000000123 0.000000000123 0.000000000123
151 3 0.0000000000123 0.00000000123 0.00000000123
152 4 0.000000000123 0.0000000123 0.0000000123
153 5 0.00000000123 0.000000123 0.000000123
154 6 0.0000000123 0.00000123 0.00000123
155 7 0.000000123 0.0000123 0.0000123
156 8 0.00000123 0.000123 0.000123
157 9 0.0000123 0.00123 0.00123
158 10 0.000123 0.0123 0.0123
159 11 0.00123 0.123 0.123
160 12 0.0123 1.23 1.23
161 13 0.123 12.3 12.3
162 14 1.23 123 123
163 Code
164 tibble::tibble(default = num(100 + 1:3 * 0.001), extra1 = num(100 + 1:3 * 0.001,
165 extra_sigfig = TRUE), extra2 = num(100 + 1:3 * 1e-04, extra_sigfig = TRUE),
166 extra3 = num(10000 + 1:3 * 1e-05, extra_sigfig = TRUE))
167 Output
168 # A tibble: 3 x 4
169 default extra1 extra2 extra3
170 <num> <num> <num> <num>
171 1 100. 100.001 100.0001 10000.00001
172 2 100. 100.002 100.0002 10000.00002
173 3 100. 100.003 100.0003 10000.00003
174
175 # many digits
176
177 Code
178 num(123456789 * 10^(-9:0))
179 Output
180 <pillar_num[10]>
181 [1] 0.123 1.23 12.3 123. 1235.
182 [6] 12346. 123457. 1234568. 12345679. 123456789
183 Code
184 num(123456789 * 10^(-9:1))
185 Output
186 <pillar_num[11]>
187 [1] 1.23e-1 1.23e+0 1.23e+1 1.23e+2 1.23e+3 1.23e+4 1.23e+5 1.23e+6 1.23e+7
188 [10] 1.23e+8 1.23e+9
189 Code
190 num(123456789 * 10^(-9:1), notation = "dec")
191 Output
192 <pillar_num(dec)[11]>
193 [1] 0.123 1.23 12.3 123. 1235.
194 [6] 12346. 123457. 1234568. 12345679. 123456789
195 [11] 1234567890
196 Code
197 num(123456789 * 10^(-9:1), notation = "sci")
198 Output
199 <pillar_num(sci)[11]>
200 [1] 1.23e-1 1.23e+0 1.23e+1 1.23e+2 1.23e+3 1.23e+4 1.23e+5 1.23e+6 1.23e+7
201 [10] 1.23e+8 1.23e+9
202 Code
203 num(123456789 * 10^(-9:1), notation = "eng")
204 Output
205 <pillar_num(eng)[11]>
206 [1] 123. e-3 1.23e+0 12.3 e+0 123. e+0 1.23e+3 12.3 e+3 123. e+3
207 [8] 1.23e+6 12.3 e+6 123. e+6 1.23e+9
208 Code
209 num(123456789 * 10^(-9:1), notation = "si")
210 Output
211 <pillar_num(si)[11]>
212 [1] 123. m 1.23 12.3 123. 1.23k 12.3 k 123. k 1.23M 12.3 M
213 [10] 123. M 1.23G
214 Code
215 num(123456789 * 10^(-9:1), notation = "sci", fixed_exponent = -Inf)
216 Output
217 <pillar_num(sci)|-Inf[11]>
218 [1] 1.23 12.3 123. 1235. 12346.
219 [6] 123457. 1234568. 12345679. 123456789 1234567890
220 [11] 12345678900
221 Code
222 num(123456789 * 10^(-9:1), notation = "eng", fixed_exponent = -Inf)
223 Output
224 <pillar_num(eng)|-Inf[11]>
225 [1] 123. 1235. 12346. 123457. 1234568.
226 [6] 12345679. 123456789 1234567890 12345678900 123456789000
227 [11] 1234567890000
228 Code
229 num(123456789 * 10^(-9:1), notation = "si", fixed_exponent = -Inf)
230 Output
231 <pillar_num(si)|-Inf[11]>
232 [1] 123. 1235. 12346. 123457. 1234568.
233 [6] 12345679. 123456789 1234567890 12345678900 123456789000
234 [11] 1234567890000
235 Code
236 num(123456789 * 10^(-9:1), notation = "sci", fixed_exponent = -3)
237 Output
238 <pillar_num(sci)|-3[11]>
239 Fixed exponent: [e-3]
240 [1] 123. 1235. 12346. 123457. 1234568.
241 [6] 12345679. 123456789 1234567890 12345678900 123456789000
242 [11] 1234567890000
243 Code
244 num(123456789 * 10^(-9:1), notation = "sci", fixed_exponent = 3)
245 Output
246 <pillar_num(sci)|3[11]>
247 Fixed exponent: [e3]
248 [1] 0.000123 0.00123 0.0123 0.123 1.23
249 [6] 12.3 123. 1235. 12346. 123457.
250 [11] 1234568.
251 Code
252 num(123456789 * 10^(-9:1), notation = "sci", fixed_exponent = Inf)
253 Output
254 <pillar_num(sci)|Inf[11]>
255 [1] 0.000000000123 0.00000000123 0.0000000123 0.000000123 0.00000123
256 [6] 0.0000123 0.000123 0.00123 0.0123 0.123
257 [11] 1.23
258
259 # sigfig and digits
260
261 Code
262 num(c(578890.23, 240234.131, 40234.1))
263 Output
264 <pillar_num[3]>
265 [1] 578890. 240234. 40234.
266 Code
267 num(c(578890.23, 240234.131, 40234.1), sigfig = 6)
268 Output
269 <pillar_num:6[3]>
270 [1] 578890. 240234. 40234.1
271 Code
272 num(c(578890.23, 240234.131, 40234.1), sigfig = 7)
273 Output
274 <pillar_num:7[3]>
275 [1] 578890.2 240234.1 40234.1
276 Code
277 num(c(578890.23, 240234.131, 40234.1), sigfig = 8)
278 Output
279 <pillar_num:8[3]>
280 [1] 578890.23 240234.13 40234.1
281 Code
282 num(c(578890.23, 240234.131, 40234.1), sigfig = 9)
283 Output
284 <pillar_num:9[3]>
285 [1] 578890.23 240234.131 40234.1
286 Code
287 num(c(578890.23, 240234.131, 40234.1), digits = 2)
288 Output
289 <pillar_num:.2![3]>
290 [1] 578890.23 240234.13 40234.10
291 Code
292 num(c(578890.23, 240234.131, 40234.1), digits = 3)
293 Output
294 <pillar_num:.3![3]>
295 [1] 578890.230 240234.131 40234.100
296 Code
297 num(c(578890.23, 240234.131, 40234.1), digits = 4)
298 Output
299 <pillar_num:.4![3]>
300 [1] 578890.2300 240234.1310 40234.1000
301 Code
302 num(c(578890.23, 240234.131, 40234.1), digits = -2)
303 Output
304 <pillar_num:.2[3]>
305 [1] 578890.23 240234.13 40234.1
306 Code
307 num(c(578890.23, 240234.131, 40234.1), digits = -3)
308 Output
309 <pillar_num:.3[3]>
310 [1] 578890.23 240234.131 40234.1
311 Code
312 num(c(578890.23, 240234.131, 40234.1), digits = -4)
313 Output
314 <pillar_num:.4[3]>
315 [1] 578890.23 240234.131 40234.1
316
317 # forced digits
318
319 Code
320 pillar(num(1:3, digits = 2))
321 Output
322 <pillar>
323 <num:.2!>
324 1.00
325 2.00
326 3.00
327 Code
328 pillar(num(1:3, digits = 5))
329 Output
330 <pillar>
331 <num:.5!>
332 1.00000
333 2.00000
334 3.00000
335
336 # all NA
337
338 Code
339 pillar(num(NA_real_, digits = 2))
340 Output
341 <pillar>
342 <num:.2!>
343 NA
344 Code
345 pillar(num(NA_real_, notation = "si"))
346 Output
347 <pillar>
348 <si>
349 NA
350 Code
351 pillar(num(NA_real_, notation = "sci"))
352 Output
353 <pillar>
354 <sci>
355 NA
356 Code
357 pillar(num(NA_real_, notation = "eng"))
358 Output
359 <pillar>
360 <eng>
361 NA
362 Code
363 pillar(num(NA_real_, notation = "sci", fixed_exponent = -1))
364 Output
365 <pillar>
366 [e-1]
367 NA
368 Code
369 pillar(num(NA_real_, notation = "sci", fixed_exponent = -Inf))
370 Output
371 <pillar>
372 <sci>
373 NA
374
375 # some NA
376
377 Code
378 pillar(num(c(NA_real_, 1000), digits = 2))
379 Output
380 <pillar>
381 <num:.2!>
382 NA
383 1000.00
384 Code
385 pillar(num(c(NA_real_, 1000), notation = "si"))
386 Output
387 <pillar>
388 <si>
389 NA
390 1k
391 Code
392 pillar(num(c(NA_real_, 1000), notation = "sci"))
393 Output
394 <pillar>
395 <sci>
396 NA
397 1e3
398 Code
399 pillar(num(c(NA_real_, 1000), notation = "eng"))
400 Output
401 <pillar>
402 <eng>
403 NA
404 1e3
405 Code
406 pillar(num(c(NA_real_, 1000), notation = "sci", fixed_exponent = -1))
407 Output
408 <pillar>
409 [e-1]
410 NA
411 10000
412 Code
413 pillar(num(c(NA_real_, 1000), notation = "sci", fixed_exponent = -Inf))
414 Output
415 <pillar>
416 [e3]
417 NA
418 1
419
420 # arithmetics
421
422 Code
423 num(1) + 2
424 Output
425 <pillar_num[1]>
426 [1] 3
427 Code
428 1 + num(2)
429 Output
430 <pillar_num[1]>
431 [1] 3
432 Code
433 1L + num(2)
434 Output
435 <pillar_num[1]>
436 [1] 3
437 Code
438 num(3.23456, sigfig = 4) - num(2)
439 Output
440 <pillar_num:4[1]>
441 [1] 1.235
442 Code
443 num(3, digits = 2) * num(4, sigfig = 2)
444 Output
445 <pillar_num:.2![1]>
446 [1] 12.00
447 Code
448 -num(2)
449 Output
450 <pillar_num[1]>
451 [1] -2
452
453 # mathematics
454
455 Code
456 min(num(1:3, label = "$"))
457 Output
458 <pillar_num{$}[1]>
459 [1] 1
460 Code
461 mean(num(1:3, notation = "eng"))
462 Output
463 <pillar_num(eng)[1]>
464 [1] 2e0
465 Code
466 sin(num(1:3, label = "%", scale = 100))
467 Output
468 <pillar_num{%}*100[3]>
469 [1] 84.1 90.9 14.1
470 Code
471 sum(num(c(1:3, NA)), na.rm = TRUE)
472 Output
473 <pillar_num[1]>
474 [1] 6
475
476 # formatting
477
478 Code
479 format(num(-1:3))
480 Output
481 [1] "-1" " 0" " 1" " 2" " 3"
482 Code
483 format(num(-1:3), trim = TRUE)
484 Output
485 [1] "-1" "0" "1" "2" "3"
486
487 # attribute
488
489 Code
490 set_num_opts(1, sigfig = 2, fixed_exponent = -Inf)
491 Output
492 [1] 1
493 attr(,"pillar")
494 pillar_num:2|-Inf
495 Code
496 set_num_opts(1000, digits = 2, notation = "eng")
497 Output
498 [1] 1000
499 attr(,"pillar")
500 pillar_num(eng):.2!
501