hadley/scales — Issue #7: Infelicities with scientific_format()
Author: djmurphy420
Created: 2011-11-27 22:24:05+00:00
State: open

Re: scientific_format() output vs. comma_format() output

Issue: comma_format()(number) does a better job of outputting scientific notation than scientific_format().

This behavior was triggered while testing graphics examples in the scales package.

# Simple examples using comma_format():
> comma_format()(1e6)
[1] "1e+06"
> comma_format(digits = 6)(1e6)
[1] "1e+06"
> comma_format(digits = 7)(1e6)
[1] "1,000,000"

> scientific_format()(246493)
[1] "246493"
> comma_format()(246493)
[1] "2.465e+05"
> comma_format(digits = 6)(246493)
[1] "246,493"

# More examples with scientific_format:

> scientific_format()(1000)
[1] "1000"
> scientific_format()(10000)
[1] "10000"
> scientific_format()(100000)
[1] "1e+05"
> scientific_format()(230000)
[1] "230000"
> scientific_format()(2300000)
[1] "2300000"
> scientific_format()(23000000)
[1] "2.3e+07"
> scientific_format()(23650000)
[1] "23650000"

It seems a minimum number of trailing digits is necessary to trigger the expected output in scientific_format(). I'll write up some tests using these examples. Similar examples using comma_format():

> comma_format()(1000)
[1] "1,000"
> comma_format()(4675)
[1] "4,675"
> comma_format()(10000)
[1] "1e+04"
> comma_format()(12456)
[1] "1.246e+04"
> comma_format()(1e5)
[1] "1e+05"
> comma_format()(230000)
[1] "2.3e+05"
> comma_format()(2300000)
[1] "2.3e+06"
> comma_format()(23650000)
[1] "2.365e+07"
> comma_format(digits = 8)(23650000)
[1] "23,650,000"