Skip to content

Infelicities with scientific_format() #7

Closed

Description

@djmurphy420

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"

Activity

  1. baptiste commented on Nov 28, 2011

    @baptiste

    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.

  2. djmurphy420 commented on Nov 28, 2011

    @djmurphy420
    Author

    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)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions