From tplate at acm.org  Fri Jan  4 06:16:05 2008
From: tplate at acm.org (Tony Plate)
Date: Thu, 03 Jan 2008 22:16:05 -0700
Subject: [Rd] as.Date.numeric origin default
In-Reply-To: <e8e755250712302153ha84354bw53f14a280f22506@mail.gmail.com>
References: <e8e755250712302153ha84354bw53f14a280f22506@mail.gmail.com>
Message-ID: <477DC115.4040303@acm.org>

Seems like it makes sense to have a default origin of 1970-01-01 for 
as.Date.numeric().  Are there any strong arguments for requiring users 
to specify the origin for every invocation of as.Date.numeric()?

The code could be:

as.Date.numeric <- function(x, origin="1970-01-01", ...)
{
    if ((missing(origin) && nargs()==1)
        || (is.character(origin) && origin=="1970-01-01" && nargs()==2))
        return(structure(as.integer(x), class="Date"))
    as.Date(origin, ...) + as.integer(x)
}

I guess the use of as.integer(x) is debatable, but using it seems 
consistent with the "Details" section of ?Date.

-- Tony Plate

Jeff Ryan wrote:
> R-devel,
>
> I would like to second Gabor Grothendieck's request from September (
> http://www.nabble.com/as.Date.numeric-to12962733.html#a12962733 )
> on adding a default value (1970-01-01) to the origin argument of
> as.Date.numeric.
>
> I realize there is good reason to allow for origin to be specified,
> but I don't see why it must be up to the user at each and every
> invocation if most (if not all) users will simply be using 1970-01-01.
>
> My first contact was building quantmod for CRAN - many more hidden
> errors occur as I test  on R-devel.  It just seems to me to be an easy
> compromise to what will undoubtedly cost many hours of debugging
> across all packages/users.
>
> Thank you for your consideration,
> Jeff Ryan
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



[Rd] as.Date.numeric origin default
Tony Plate