Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative method to display numeric values that were truncated for display #104

Closed
lorenzwalthert opened this issue Mar 2, 2018 · 2 comments

Comments

@lorenzwalthert
Copy link

lorenzwalthert commented Mar 2, 2018

Essentially migrating tidyverse/tibble#362 (comment).

with pillar 1.2.1 and tibble 1.4.2 I get this

library(tibble)
library(purrr)
tibble(
  integer = sample(100),
  numeric = integer + runif(100, 0, 10e-4),
  long_string = rerun(100, paste0(sample(rep(letters, 10)), collapse = "")) %>% flatten_chr()
)
#> # A tibble: 100 x 3
#>    integer numeric long_string                                            
#>      <int>   <dbl> <chr>                                                  
#>  1      51    51.0 zwsbmmgoegfginnikiyidrqcvkbivgkqtqpeblkezcntutkrmzchcm…
#>  2      37    37.0 qovlyzbtbyrfjnrxvitqdvjefyeskwfqdkkxjgirceepdnyzhglgas…
#>  3      33    33.0 lkfgpmzekxvtdlytkzhqkxunuhccfspefajweoiaeficvzgqqpvevf…
#>  4      69    69.0 fgihsvbyqcxbmynuxuywliptbabzomrbnvgbdelvsqmmscmwiknskg…
#>  5      84    84.0 zlrfncxjqvtllvmmzddslyeoiwtswyaexnxkfmwebbxmpmltnstfhe…
#>  6      60    60.0 lunkdilxuipgkvnixxumjsnqilcqskqyyxeyxpmpzavroxjqauwcga…
#>  7      77    77.0 wklbnoexoyimgdwyywzoosnupqejygsahxxfmugwynhnqfallvrqvc…
#>  8      74    74.0 rgrtqshfbxomhhilvurhmdqgwuveeldugulmtueybznfvrcpqvwiia…
#>  9      91    91.0 iswngaunersfosinwepihmznjwqxfeitmdgkisthugggxmggovsvyc…
#> 10      21    21.0 akadobtgrfnhjgbndrgglfalglvzkifibxkniqzqizexyfyfcwiicw…
#> # ... with 90 more rows

Created on 2018-03-02 by the reprex package (v0.2.0).

I think it's hard to guess that 96.0 does not represent the same value as 96, at least for me. Hence, I propose to represent numbers that were truncated for display (more) similar to truncated text: With three trailing dots after the decimal dot (that's at least what it looks like on my mac).

As pointed out by @krlmlr in tidyverse/tibble#362 (comment), I could increase the pillar option to show more digits, but I guess my point is not that I want to know the exact number, but rather I think it would be beneficial to see at first glance whether a number is truncated for display or not, in an intuitive way. So the above would become

library(tibble)
library(purrr)
tibble(
  integer = sample(100),
  numeric = integer + runif(100, 0, 10e-4),
  long_string = rerun(100, paste0(sample(rep(letters, 10)), collapse = "")) %>% flatten_chr()
)
#> # A tibble: 100 x 3
#>    integer numeric long_string                                            
#>      <int>   <dbl> <chr>                                                  
#>  1      51    51.… zwsbmmgoegfginnikiyidrqcvkbivgkqtqpeblkezcntutkrmzchcm…
#>  2      37    37.… qovlyzbtbyrfjnrxvitqdvjefyeskwfqdkkxjgirceepdnyzhglgas…
#>  3      33    33.… lkfgpmzekxvtdlytkzhqkxunuhccfspefajweoiaeficvzgqqpvevf…
#>  4      69    69.… fgihsvbyqcxbmynuxuywliptbabzomrbnvgbdelvsqmmscmwiknskg…
#>  5      84    84.… zlrfncxjqvtllvmmzddslyeoiwtswyaexnxkfmwebbxmpmltnstfhe…
#>  6      60    60.… lunkdilxuipgkvnixxumjsnqilcqskqyyxeyxpmpzavroxjqauwcga…
#>  7      77    77.… wklbnoexoyimgdwyywzoosnupqejygsahxxfmugwynhnqfallvrqvc…
#>  8      74    74.… rgrtqshfbxomhhilvurhmdqgwuveeldugulmtueybznfvrcpqvwiia…
#>  9      91    91.… iswngaunersfosinwepihmznjwqxfeitmdgkisthugggxmggovsvyc…
#> 10      21    21.… akadobtgrfnhjgbndrgglfalglvzkifibxkniqzqizexyfyfcwiicw…
#> # ... with 90 more rows

Created on 2018-03-02 by the reprex package (v0.2.0).

@krlmlr
Copy link
Member

krlmlr commented Mar 2, 2018

The numbers in the numeric column are truncated not for display, but because by default only 3 significant figures are requested. This is what is shown in this column. The .0 suggests that there's more, whole numbers don't have the 0 after the decimal dot.

We see more if we ask for 6 significant figures:

library(tibble)
library(purrr)
options(pillar.sigfig = 6)
tibble(
  integer = sample(100),
  numeric = integer + runif(100, 0, 10e-4),
  long_string = rerun(100, paste0(sample(rep(letters, 10)), collapse = "")) %>% flatten_chr()
)
#> # A tibble: 100 x 3
#>    integer numeric long_string                                            
#>      <int>   <dbl> <chr>                                                  
#>  1      97 97.0001 bggdngfamupzwnoqtgnpeqxgepycbzoojruswgoucxowflljkhonep…
#>  2      13 13.0009 mzxwfaftnmugqiaukxjkwxzqmorukcufbsxaklttwsalglxpsuiijw…
#>  3      12 12.0008 zomszzwwrvajedxgaqhomgivvgdltlyvhvhcdckpfxxljeunfjupcc…
#>  4      83 83.0004 niekxtluwrkifjgiuovvgwzudsugibqkfmlkdcuzdjygpedlobbhym…
#>  5      58 58.0001 zzfieszqpotnneexxngltoemlqptkqbpmlptwpnegctcvdfcvtmonr…
#>  6      93 93.0006 qzdafvochukcfpazpsbgybtgncdxchvxatuzqivrrwhefogzimspuq…
#>  7      16 16.0005 rbfhrijvbskyamftsvwgduopeqevmivomepeqddjgrwldirnbmipwk…
#>  8      18 18.0003 iyvvaxwugorelcghunzcbqlrtewissyfpsxkedrxczjkzxvavqvhtn…
#>  9      38 38.0002 przmtjfypppokwmgbcxbuqxmqigwkllyuewbiqvialnyneesysupoq…
#> 10      21 21.0004 ztmqatqjxswfyqgwdpwwxwjnsunmpqizcofrmxbxcczjirysruvuod…
#> # ... with 90 more rows

Created on 2018-03-03 by the reprex package (v0.2.0).

Closing, please open a new issue in tibble if you still think the behavior is wrong even with more significant digits shown.

@krlmlr krlmlr closed this as completed Mar 2, 2018
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants