Bug 16982 - new option to prettyNum() for big numbers
Summary: new option to prettyNum() for big numbers
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-07-07 13:53 UTC by Marcos F
Modified: 2016-07-13 06:37 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcos F 2016-07-07 13:53:14 UTC
Would you consider to add some functionality to prettyNum()?


#Abbreviate some big numbers using a suffix "k", "M":
abbreviate_num <- function (i) {
    n <- floor(log(i, 1000))
    n <- ifelse(n>2, 2, n)
    paste0(round(i/(1000^n), 2), c("", "k", "M")[n+1])
}
abbreviate_num(222)
[1] "222"
abbreviate_num(1422)
[1] "1.42k"
abbreviate_num(14223)
[1] "14.22k"
abbreviate_num(14223323)
[1] "14.22M"
Comment 1 Martin Maechler 2016-07-13 06:37:56 UTC
Interesting... but we do have scientific notation already (1422 = 1.422e3), and I'd tend to emphasize people should know how to read that.

Still, if someone would provide patches for supporting such units as output,
it should of course encompass *all* SI units, not just "k" and "M"..

In this context, do look at  object.size() formatting / units and also PR#16649 :
https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16649