Bug 15303 - formatC(DatesObject) requires digits=16 to get right string
Summary: formatC(DatesObject) requires digits=16 to get right string
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: R 3.0.0
Hardware: All All
: P5 minor
Assignee: R-core
Depends on:
Reported: 2013-05-03 21:06 UTC by Bill Dunlap
Modified: 2013-07-15 12:25 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2013-05-03 21:06:22 UTC
formatC(x) is not parameterized to work with Date objects so you need to make it use full precision to get the right result:

> days <- as.Date(c("2012-02-02", "2012-03-03", "2012-05-05"))
> format(days) # good
[1] "2012-02-02" "2012-03-03" "2012-05-05"
> formatC(days) # bad
[1] "2012-01-31" "2012-03-01" "2012-04-30"
> formatC(days, digits=16)  # good
[1] "2012-02-02" "2012-03-03" "2012-05-05"

Perhaps this is in its help file, but I cannot look at that.
Comment 1 Brian Ripley 2013-07-15 12:25:53 UTC
Why are you using formatC on "Date" objects?  That is contrary to the documentation:

From the help file

       x: an atomic numerical or character object, possibly ‘complex’
          only for ‘prettyNum()’, typically a vector of real numbers.

You have created an invalid object (class "Date", mode "character").