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

From: <Robert.McGehee_at_geodecapital.com>
Date: Wed 20 Sep 2006 - 15:43:53 GMT


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.

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 Received on Thu Sep 21 01:59:02 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 - 17:30:08 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.