Base R offers the"digits" and"scipen"options to control the number of significant digits and the switch toscientific notation. For tibble, the options"pillar.sigfig" and"pillar.max_dec_width"fulfill a similar purpose. This vignette showcases similarities anddifferences. See?pillar::pillar_options and?tibble_options for an overview over all options.
The default forgetOption("digits") is 7, whereas the"pillar.sigfig" option defaults to 3. In the defaultsetting, pillar prints the first three digits only (i.e. the digits thatrepresent > 99.9% of the value of the number). Another difference isthat pillar will show at most the specified number of significantdigits, even if space is available. The rationale is to allow a quickglance over the most significant digits of a number, without spendingtoo much horizontal space and without distraction from insignificantdigits.
Terminal zeros are only shown in pillar if there is a nonzero valuepast the significant digits shown. This is in contrast to base R whereterminal zeros are always shown if there is space, but hidden if thevalue is too insignificant:
A trailing decimal separator is shown if there is a fractional partbut the integer part already exceeds the significant digits. Thepresence of the decimal separator doesnot indicatethat the number is larger, only that there exists a nonzero fractionalpart:
To show more significant digits, set the"pillar.sigfig"option to a larger value:
options(digits =7)options(pillar.sigfig =7)c(1.2345,12.345,123.45,1234.5,12345)#> [1] 1.2345 12.3450 123.4500 1234.5000 12345.0000tibble(x =c(1.2345,12.345,123.45,1234.5,12345))#> # A tibble: 5 × 1#> x#> <dbl>#> 1 1.2345#> 2 12.345#> 3 123.45#> 4 1234.5#> 5 12345Setting"pillar.sigfig" to a larger value will notenhance the display with digits deemed insignificant:
Both base R and pillar switch to scientific notation when the decimalrepresentation becomes too wide. The largergetOption("scipen"), the stronger the resistance toswitching to scientific notation. The default0 seems to beanchored at 13 digits for the integer part.
123456789012#> [1] 123456789012123456789012.3#> [1] 1234567890121234567890123#> [1] 1.234568e+121234567890123.4#> [1] 1.234568e+12options(scipen =1)1234567890123#> [1] 123456789012312345678901234#> [1] 1.234568e+1312345678901234.5#> [1] 1.234568e+13The"pillar.max_dec_width" option is similar, itindicates the width that must be exceeded for a switch to scientificnotation to happen. This width includes the decimal separator.
tibble(x =123456789012)#> # A tibble: 1 × 1#> x#> <dbl>#> 1 123456789012tibble(x =123456789012.3)#> # A tibble: 1 × 1#> x#> <dbl>#> 1 123456789012.tibble(x =1234567890123)#> # A tibble: 1 × 1#> x#> <dbl>#> 1 1234567890123tibble(x =1234567890123.4)#> # A tibble: 1 × 1#> x#> <dbl>#> 1 1.234568e12options(pillar.max_dec_width =14)tibble(x =1234567890123)#> # A tibble: 1 × 1#> x#> <dbl>#> 1 1234567890123tibble(x =12345678901234)#> # A tibble: 1 × 1#> x#> <dbl>#> 1 12345678901234tibble(x =12345678901234.5)#> # A tibble: 1 × 1#> x#> <dbl>#> 1 1.234568e13To avoid switching to scientific notation, set the"pillar.max_dec_width" option to a large value. Note thatif the required width is not available to show the column, it will notbe shown at all in this case. Thenotation argument tonum() offers more options:
num(12345678901234567,notation ="dec")#> <pillar_num(dec)[1]>#> [1] 12345678901234568num(12345678901234567,notation ="sci")#> <pillar_num(sci)[1]>#> [1] 1.234568e16num(12345678901234567,notation ="eng")#> <pillar_num(eng)[1]>#> [1] 12.34568e15num(12345678901234567,notation ="si")#> <pillar_num(si)[1]>#> [1] 12.34568P