From gmbecker at ucdavis.edu  Thu Aug 21 01:52:39 2014
From: gmbecker at ucdavis.edu (Gabriel Becker)
Date: Wed, 20 Aug 2014 16:52:39 -0700
Subject: [Rd] as.Date.character suggestion
In-Reply-To: <CA+hbrhUaZgCBjfwhT7Nnu9g3Xjsub_EdHSvmz5KksSFwgNS_4A@mail.gmail.com>
References: <CA+hbrhUZnZMMPL9gfK3rYzR7z9K8tEwsyFC2VOa_y0Lu254bZQ@mail.gmail.com>
	<53F5029C.3080909@gmail.com>
	<CA+hbrhUaZgCBjfwhT7Nnu9g3Xjsub_EdHSvmz5KksSFwgNS_4A@mail.gmail.com>
Message-ID: <CADwqtCMLWqOJ5KF4HWdF63iOpMwafDjA1bxTaPpJHe6+2Q2jvA@mail.gmail.com>

Could do both to preserve bc...

if(missing(format) || !nchar(format))

~G


On Wed, Aug 20, 2014 at 1:50 PM, Peter Langfelder <
peter.langfelder at gmail.com> wrote:

> That would be my preferred solution, but it would break backwards
> compatibility for format="", so others may disagree.
>
> Peter
>
> On Wed, Aug 20, 2014 at 1:18 PM, Duncan Murdoch
> <murdoch.duncan at gmail.com> wrote:
> > On 20/08/2014, 4:11 PM, Peter Langfelder wrote:
> >> The default format="" in as.Date.character is supremely confusing. The
> >> help shows as.Date defined as
> >>
> >> ## S3 method for class 'character'
> >>      as.Date(x, format = "", ...)
> >>
> >> yet the function behaves very differently when format is not specified
> >> and when it is specified to its default:
> >>
> >> as.Date("2012-01-01")
> >> [1] "2012-01-01"
> >>> as.Date("2012-01-01", format = "")
> >> [1] "2014-08-20"  ### Gives today.
> >>
> >>
> >> The default setting is never used, because if format is not given,
> >> values "%Y-%m-%d" and "%Y/%m/%d" are tried for it (rather than "").
> >>
> >> My suggestion is to leave out the default "" for format in as.Date:
> >>
> >> as.Date(x, format, ...)
> >>
> >> If this causes a conflict in the S3 dispatching, at least indicate in
> >> the help that the default is never used and the function works
> >> differently if format is specified to its default.
> >
> > Wouldn't it be simpler to change the test from
> >
> > if (missing(format))
> >
> > to
> >
> > if (format == "")
> >
> > ?
> >
> > Duncan Murdoch
> >
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Gabriel Becker
Graduate Student
Statistics Department
University of California, Davis

	[[alternative HTML version deleted]]



[Rd] as.Date.character suggestion
Gabriel Becker