[R] ISOdate() and strptime()

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Nov 22 20:55:30 CET 2003


Confirmation that this *is* an OS-specific problem: A professional 
implementation of the POSIX standard (Solaris) gets all of these correct.

Your so-called OS lacks any implementation of strptime, so we borrowed one 
from glibc.  Unfortunately, that is buggy, even to the extent that

unclass(strptime("2003-22-20", format="%Y-%m-%d"))
unclass(strptime("2003 22 20", format="%Y %m %d"))

give different answers!  (And RH8.0 gives the same answers as the 
substitute code used on R for Windows.)

I believe Simon Fear owes the R-developers a public apology for his (not
properly referenced in the archives) reply to this thread.

BDR

On Fri, 14 Nov 2003, Prof Brian Ripley wrote:

> On Fri, 14 Nov 2003, RINNER Heinrich wrote:
> 
> > Dear R-people!
> > 
> > I am using R 1.8.0, under Windows XP.
> > While using ISOdate() and strptime(), I noticed the following behaviour when
> > "wrong" arguments (e.g., months>12) are given to these functions:
> > 
> > > ISOdate(year=2003,month=2,day=20) #ok
> > [1] "2003-02-20 13:00:00 Westeuropäische Normalzeit"
> > > ISOdate(year=2003,month=2,day=30) #wrong day, but returns a value
> > [1] "2003-03-02 13:00:00 Westeuropäische Normalzeit"
> > > ISOdate(year=2003,month=2,day=35) #wrong day, and returns NA
> > [1] NA
> > > ISOdate(year=2003,month=2,day=40) #wrong day, but returns a value
> > [1] "2003-02-04 01:12:00 Westeuropäische Normalzeit"
> > > ISOdate(year=2003,month=22,day=20) #wrong month, but returns a value
> > [1] "2003-02-02 21:12:00 Westeuropäische Normalzeit"
> > 
> > And almost the same with strptime():
> > > strptime("2003-02-20", format="%Y-%m-%d")
> > [1] "2003-02-20"
> > > strptime("2003-02-30", format="%Y-%m-%d")
> > [1] "2003-03-02"
> > > strptime("2003-02-35", format="%Y-%m-%d")
> > [1] NA
> > > strptime("2003-02-40", format="%Y-%m-%d")
> > [1] "2003-02-04"
> > > strptime("2003-22-20", format="%Y-%m-%d")
> > [1] NA
> > 
> > Is this considered to be a user error ("If you put garbage in, expect to get
> > garbage out"), or would it be safer to generally return Nas, as in
> > ISOdate(year=2003,month=2,day=35)?
> 
> Expect to get the best guess at what you intended, and expect this to 
> depend on your OS.
> 
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list