-
Notifications
You must be signed in to change notification settings - Fork 37
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
Feature Request: pillar.round = FALSE #97
Comments
Thanks. I agree we need to think more about how to represent numbers of the same magnitude but with subtle differences. |
+1 on this feature. I understand the motivation for showing only significant digits, and I'd even be prepared to agree that this makes sense when the emphasis is on analysis of measured, physical data. However, when we're working with certain types of data (currency values) or when we're working on a pipeline of functions to perform some data manipulation (rather than just an "analysis") and trying to verify that the logic is working correctly at each step, this default of aggressive, three-sigdig rounding is both surprising and confusing. This is a case where vanilla R basically got it right. The logic in
I would suggest that the proposed In fact, if I had may way, this would be the default behavior, though I understand why some people would prefer the current default with its pre-rounded answers. |
Curious as to the status of this. I've been struggling all morning trying to make a summary tibble display a consistent number of decimal places (i.e., simply match the data as read in from Excel with two decimals). I am working with a group of consultants who are ride-or-die Excel folks, and if I can't prove to them that R (+tidyverse) will make their life better rather than more confusing and complicated, I will struggle to get traction. This is an example of something that is effortless in Excel ("I want to see these numbers with three decimals" click, click done), but that has now taken me an hour to learn that other than changing My only option as I see it is to produce a gt (or similar) table -- a whole other step and chunk of code -- just to control something that is a click or two in Excel. Now when a colleague asks me, "why is it rounding this column but not those?" "can you make it match the spreadsheet?" and I have to say, "no, we don't get to do that, because... something." I will get a snort and a pat on the head and they will go back to their rectangles. Which makes me sad. Rounding, please! |
Spent an hour trying to understand where all the decimal points are gone, before the trailing |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks for the clarification. It looks like many comments in this thread are discussing the difference between vector printing in pillar and in base R: we focus on significant digits, base R always shows
I opened #312 to discuss the issue of fixed decimal digits, and hid the most recent comments. The original post here is about a different problem: show the details in the my_numbers <- c(233, 486, 565, 785)
df <- data.frame(
big = 1000 * my_numbers + 23,
straddle = my_numbers / 1000 + 100,
small = my_numbers / 100000
)
tbl <- tibble::as_tibble(df)
options(pillar.sigfig = 7)
df
#> big straddle small
#> 1 233023 100.233 0.00233
#> 2 486023 100.486 0.00486
#> 3 565023 100.565 0.00565
#> 4 785023 100.785 0.00785
tbl
#> # A tibble: 4 x 3
#> big straddle small
#> <dbl> <dbl> <dbl>
#> 1 233023 100.233 0.00233
#> 2 486023 100.486 0.00486
#> 3 565023 100.565 0.00565
#> 4 785023 100.785 0.00785
options(pillar.sigfig = NULL)
options(digits = 3)
df
#> big straddle small
#> 1 233023 100 0.00233
#> 2 486023 100 0.00486
#> 3 565023 101 0.00565
#> 4 785023 101 0.00785
tbl
#> # A tibble: 4 x 3
#> big straddle small
#> <dbl> <dbl> <dbl>
#> 1 233023 100. 0.00233
#> 2 486023 100. 0.00486
#> 3 565023 101. 0.00565
#> 4 785023 101. 0.00785 Created on 2021-04-12 by the reprex package (v1.0.0) |
It looks like the following approach might work:
The following reprex proposes an implementation. We're sorting the data, looking at adjacent differences and determine the magnitude of the difference relative to the value. The decimal logarithm translates this to a number of extra significant digits. Does that make sense? Can you think about cases where library(pillar)
extra_digits <- function(x) {
x <- sort(abs(x))
delta <- diff(x)
x <- x[-1]
keep <- which((delta != 0) & is.finite(delta))
if (length(keep) == 0) {
return(0)
}
x <- x[keep]
delta <- delta[keep]
ceiling(log10(max(x / delta)))
}
num_with_extra_digits <- function(x) {
num(x, sigfig = 3 + extra_digits(x))
}
my_numbers <- c(233, 486, 565, 785)
tibble::tibble(
big = num_with_extra_digits(1000 * my_numbers + 23),
straddle = num_with_extra_digits(my_numbers / 1000 + 100),
straddle2 = num_with_extra_digits(my_numbers / 1000 + 1000),
straddle3 = num_with_extra_digits(my_numbers / 10000 + 10000),
small = num_with_extra_digits(my_numbers / 100000)
)
#> # A tibble: 4 × 5
#> big straddle straddle2 straddle3 small
#> <num:4> <num:7> <num:8> <num:10> <num:4>
#> 1 233023 100.233 1000.233 10000.0233 0.00233
#> 2 486023 100.486 1000.486 10000.0486 0.00486
#> 3 565023 100.565 1000.565 10000.0565 0.00565
#> 4 785023 100.785 1000.785 10000.0785 0.00785 Created on 2021-07-26 by the reprex package (v2.0.0.9000) |
Hey @krlmlr as I originally opened this issue I wanted to answer your question - other folks who've commented may have additional comments. This solves my needs. I'll think about cases where it doesn't work as expected. I see that |
Thanks. I checked the documentation, there is a path that leads from In the meantime I'll extend |
- `num()` gains `extra_sigfig` argument to automatically show more significant figures for numbers of the same magnitude with subtle differences (#97).
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. |
It would be beneficial to have an option
pillar.round
to control the rounding of numbers that straddle 0 - 1.In the following example the
straddle
column has been subject to rounding aspillar.sigfig = 3
by default:In order to display the fractional component of
straddle
straddle we need to massively pad thesmall
column withpillar.sigfig = 7
It would be useful for the following to work (note the use of *233* to indicate the portion of the output that is highlighted thanks to
pillar.subtle = TRUE
)I appreciate the comment from @hadley here #40 (comment) about using a trailing
.
but I think this is a different problem to what was discussed in that issue.The text was updated successfully, but these errors were encountered: