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

Duncan Murdoch murdoch at stats.uwo.ca
Wed Sep 20 19:19:18 CEST 2006


On 9/20/2006 11:43 AM, Robert.McGehee at 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 at geodecapital.com
> 
> 
> 
> This e-mail, and any attachments hereto, are intended for us...{{dropped}}
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel




More information about the R-devel mailing list