Re: [Rd] seq.Date not accepting NULL length.out (PR#9239)

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed 20 Sep 2006 - 17:19:18 GMT

On 9/20/2006 11:43 AM, Robert.McGehee@geodecapital.com wrote:
> There seems to be a bug in seq.Date such that it will not allow the user
> to pass in length.out =3D NULL, despite the fact that this is the =
> default
> argument.

Yes, that's a bug: the test is "is.missing", when it should be "is.null". I'll fix it. Thanks!

Duncan Murdoch

>
> For example:

>> dt1 <- as.Date("2004-12-31")
>> dt2 <- as.Date("2005-12-31")
>> seq.Date(dt1, dt2, length.out =3D NULL, by =3D "month")

> Error in seq.Date(dt1, dt2, length.out =3D NULL, by =3D "day") :=20
> 'length.out' must be of length 1
>
> This might be an issue if I want to wrap seq.Date in another function
> that reports or modifies on length.out. For instance, suppose I want to
> create a simple function that simply reports when length.out is NULL (or
> missing), as below, but otherwise works identically to seq.Date.
>
> FUN <- function(to, from, length.out =3D NULL, by, ...) {
> if (is.null(length.out)) cat("length.out is missing\n")
> seq.Date(to, from, length.out =3D length.out, by =3D by, ...)
> }
>
>> seq.Date(dt1, dt2, by =3D "month")

> [1] "2004-12-31" "2005-01-31" "2005-03-03" "2005-03-31" "2005-05-01"
> [6] "2005-05-31" "2005-07-01" "2005-07-31" "2005-08-31" "2005-10-01"
> [11] "2005-10-31" "2005-12-01" "2005-12-31"
>
>> FUN(dt1, dt2, by =3D "month")

> length.out is missing
> Error in seq.Date(dt1, dt2, length.out =3D NULL, by =3D "day") :=20
> 'length.out' must be of length 1
>
> I believe the patch to fix this error is as follows (on R2.4.0(alpha)
> Revision 39430)
> - } else if (!missing(length.out)) {
> + } else if (!missing(length.out) && !is.null(length.out)) {
>
> Another (perhaps better) patch would be to not have NULL be the default
> for length.out.
>
> HTH,
> Robert
>
> Robert McGehee
> Quantitative Analyst
> Geode Capital Management, LLC
> 53 State Street, 5th Floor | Boston, MA | 02109
> Tel: 617/392-8396 Fax:617/476-6389
> mailto:robert.mcgehee@geodecapital.com
>
>
>
> This e-mail, and any attachments hereto, are intended for us...{{dropped}}
>
> ______________________________________________
> R-devel@r-project.org mailing list
>
https://stat.ethz.ch/mailman/listinfo/r-devel


R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Sep 21 03:21:54 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 20 Sep 2006 - 21:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.