Thank you Greg and Gabor for explanations. I have some further question below.
On Thu, Jan 22, 2009 at 8:16 PM, Greg Snow <greg.s...@imail.org> wrote: > I believe the original thread was about whether the function returns NA or > stops with an error when given an invalid date (such as Feb 29 in a non-leap > year). Your question was about how as.Date returned something different > from what you expected. Related, but different enough that it probably > would have been better to start a new thread. I hope it was then okay I started a new thread. > > > For your question, the help page for as.Date includes: > > "format: A character string. The default is '"%Y-%m-%d"'. For > details see 'strftime'." > To be strict, neither "1/13/2001" nor "13/1/2001" match the format, so both should raise error, I think. Since the behaviour seem not to apply the default strictly, why ought one think "13/1/2001" will not be parsed the only reasonable way? > > And > > "Character strings are processed as far as > necessary for the format specified: any trailing characters are > ignored." > > I don't see anything in your examples that runs counter to the above. Yes they do. None of them match the format, but some parse correctly, some produce rubbish, and some raise error. Maybe you want to improve the help page fo the as.Date to say something like "The default is a sequence of numerical representations of the year, then the month, then the day, separated by one of '-', '/', ...", which make it clearer. > > Remember that computers do exactly what you tell them to do, not what you > think that they should do. Computers do exactly what they were programmed to do, and what they will do depends on what the developer told them to do when they are given certain input. I expect them to do exactly what I tell them to do, and it is to parse "1/13/2001" the only reasonable way. It seems that someone told them to do something else... Mvh. Marie [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.