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

Infelicities with scientific_format() #7

Closed
djmurphy420 opened this Issue Nov 27, 2011 · 2 comments

Comments

Projects
None yet
3 participants
@djmurphy420

djmurphy420 commented Nov 27, 2011

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"

@baptiste

This comment has been minimized.

baptiste commented Nov 28, 2011

The issue is that format() used by scientific() decides whether to use scientific notation or not (parameter scientific), whereas formatC() used by comma() has no such option. I guess using formatC for both would make sense.

@djmurphy420

This comment has been minimized.

djmurphy420 commented Nov 28, 2011

Hi Baptiste:

I put that bug report up at Hadley's request as I've been going over the examples in the scales and ggplot2 packages for future documentation purposes. I had noticed the difference between the format() and formatC() in the two functions. I had commented to Hadley after running the examples that comma_format() was generating scientific notation more reliably than scientific_format(), but when cranking out examples for the bug report, it became clearer to me that the number of digits of desired precision certainly plays a role in all of this. I'll look more closely into format() and formatC() - thanks for the comments.

I'm just starting in on all of this, so I have a lot to learn. I'm way behind the 8-ball with respect to grid and some of the programming constructs in R relative to the rest of you, so please be patient with what will probably seem like naive and silly questions at times on my part.

Dennis


From: baptiste reply@reply.github.com
To: Dennis Murphy djmurphy0420@yahoo.com
Sent: Sunday, November 27, 2011 5:04 PM
Subject: Re: [scales] Infelicities with scientific_format() (#7)

The issue is that format() used by scientific() decides whether to use scientific notation or not (parameter scientific), whereas formatC() used by comma() has no such option. I guess using formatC for both would make sense.


Reply to this email directly or view it on GitHub:
#7 (comment)

@hadley hadley closed this in 571ec73 Feb 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment