[Rd] seq.Date bug?

Steven McKinney smckinney at bccrc.ca
Tue Jan 31 23:07:02 CET 2012


> -----Original Message-----
> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org]
> On Behalf Of Jeffrey Ryan
> Sent: January-31-12 12:47 PM
> To: Dirk Eddelbuettel
> Cc: R-devel org
> Subject: Re: [Rd] seq.Date bug?
> 
> format(ISOdate(2012,1:12,1),"%b-%Y")
> 
> [1] "Jan-2012" "Feb-2012" "Mar-2012" "Apr-2012" "May-2012" "Jun-2012"
> [7] "Jul-2012" "Aug-2012" "Sep-2012" "Oct-2012" "Nov-2012" "Dec-2012"
> 
> First of the month is just as clean, and AFAIR they all have a first ;-)

>From which you can get the last...

> format(ISOdate(2012,1:12,1)-86400,"%d-%b-%Y")
 [1] "31-Dec-2011" "31-Jan-2012" "29-Feb-2012" "31-Mar-2012" "30-Apr-2012" "31-May-2012"
 [7] "30-Jun-2012" "31-Jul-2012" "31-Aug-2012" "30-Sep-2012" "31-Oct-2012" "30-Nov-2012"

... though leap seconds might require a bit more tweaking...

Steven McKinney
Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre



> 
> Jeff
> 
> On Tue, Jan 31, 2012 at 2:37 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
> >
> > On 31 January 2012 at 15:17, Duncan Murdoch wrote:
> > | On 12-01-31 2:56 PM, Dirk Eddelbuettel wrote:
> > | >
> > | > R>  seq(as.Date(Sys.Date()), by="-1 months", length=6)
> > | > [1] "2012-01-31" "2011-12-31" "2011-12-01" "2011-10-31" "2011-10-01"
> "2011-08-31"
> > | > R>
> > | >
> > | > Notice how October appears twice.
> > |
> > | >
> > | > Now, date arithmetic is gruesome but the documentation for seq.Date
> et al
> > | > does not hint it wouldn't honour the by= argument.  So a bug, or
> merely a
> > | > somewhat less than desirable features.
> > |
> > | It is giving you Jan 31, Dec 31, Nov 31, Oct 31, Sep 31, Aug 31 --
> > | except some of those months don't have 31 days, so it is converting
> > | those dates to ones that really exist.  (This is documented in
> ?seq.POSIXt.)
> > |
> > | Isn't this what you asked for?
> >
> > No as I was feeding this into format(..., "%b-%y") to create 'pretty'
> names,
> > and the double entries screw that.
> >
> > Morale:  pick a mid-month date, and shift that.
> >
> > Dirk
> >
> > | Duncan Murdoch
> > |
> > |
> > | >
> > | > (And yes, I think I know that Hadley's lubridate has code for this
> too, but
> > | > so may my RcppBDT which is sitting on top of Boost::DateTime code
> ...)
> > | >
> > | > Dirk
> > | >
> > |
> >
> > --
> > "Outside of a dog, a book is a man's best friend. Inside of a dog, it is
> too
> > dark to read." -- Groucho Marx
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 
> 
> --
> Jeffrey Ryan
> jeffrey.ryan at lemnica.com
> 
> www.lemnica.com
> www.esotericR.com
> 
> R/Finance 2012: Applied Finance with R
> www.RinFinance.com
> 
> See you in Chicago!!!!
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list