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

Robert.McGehee at geodecapital.com Robert.McGehee at geodecapital.com
Wed Sep 20 17:43:53 CEST 2006

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 =

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.


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 at geodecapital.com

This e-mail, and any attachments hereto, are intended for us...{{dropped}}

More information about the R-devel mailing list