@@ -255,22 +255,21 @@ seq.Date <- function(from, to, by, length.out = NULL, along.with = NULL, ...)
255255 if (length(length.out ) != 1L ) stop(" 'length.out' must be of length 1" )
256256 length.out <- ceiling(length.out )
257257 }
258+ if (! missing(to ) && missing(by )) {
259+ from <- as.integer(as.Date(from ))
260+ to <- as.integer(as.Date(to ))
261+ res <- seq.int(from , to , length.out = length.out )
262+ return (.Date(res ))
263+ }
264+ # # else
258265 status <- c(! missing(to ), ! missing(by ), ! is.null(length.out ))
259266 if (sum(status ) != 2L )
260267 stop(" exactly two of 'to', 'by' and 'length.out' / 'along.with' must be specified" )
261- if (missing(by )) {
262- from <- unclass(as.Date(from ))
263- to <- unclass(as.Date(to ))
264- res <- seq.int(from , to , length.out = length.out )
265- # # force double storage for consistency
266- return (.Date(as.numeric(res )))
267- }
268-
269268 if (length(by ) != 1L ) stop(" 'by' must be of length 1" )
270269 valid <- 0L
271270 if (inherits(by , " difftime" )) {
272271 by <- switch (attr(by ," units" ), secs = 1 / 86400 , mins = 1 / 1440 ,
273- hours = 1 / 24 , days = 1 , weeks = 7 ) * unclass (by )
272+ hours = 1 / 24 , days = 1 , weeks = 7 ) * as.integer (by )
274273 } else if (is.character(by )) {
275274 by2 <- strsplit(by , " " , fixed = TRUE )[[1L ]]
276275 if (length(by2 ) > 2L || length(by2 ) < 1L )
@@ -279,44 +278,37 @@ seq.Date <- function(from, to, by, length.out = NULL, along.with = NULL, ...)
279278 c(" days" , " weeks" , " months" , " quarters" , " years" ))
280279 if (is.na(valid )) stop(" invalid string for 'by'" )
281280 if (valid < = 2L ) {
282- by <- c(1 , 7 )[valid ]
281+ by <- c(1L , 7L )[valid ]
283282 if (length(by2 ) == 2L ) by <- by * as.integer(by2 [1L ])
284283 } else
285- by <- if (length(by2 ) == 2L ) as.integer(by2 [1L ]) else 1
284+ by <- if (length(by2 ) == 2L ) as.integer(by2 [1L ]) else 1L
286285 } else if (! is.numeric(by )) stop(" invalid mode for 'by'" )
287286 if (is.na(by )) stop(" 'by' is NA" )
288287
289288 if (valid < = 2L ) { # days or weeks
290- from <- unclass(as.Date(from ))
291- if (! is.null(length.out ))
292- res <- seq.int(from , by = by , length.out = length.out )
293- else {
294- to0 <- unclass(as.Date(to ))
295- # # defeat test in seq.default
296- res <- seq.int(0 , to0 - from , by ) + from
297- }
298- # # force double storage for consistency
299- res <- .Date(as.numeric(res ))
289+ from <- as.integer(as.Date(from ))
290+ res <- .Date(if (! is.null(length.out ))
291+ seq.int(from , by = by , length.out = length.out )
292+ else # defeat test in seq.default
293+ seq.int(0L , as.integer(as.Date(to )) - from , by ) + from )
300294 } else { # months or quarters or years
301295 r1 <- as.POSIXlt(from )
302296 if (valid == 5L ) { # years
303- if (missing(to )) {
304- yr <- seq.int(r1 $ year , by = by , length.out = length.out )
305- } else {
306- to0 <- as.POSIXlt(to )
307- yr <- seq.int(r1 $ year , to0 $ year , by )
308- }
309- r1 $ year <- yr
297+ r1 $ year <-
298+ if (missing(to ))
299+ seq.int(r1 $ year , by = by , length.out = length.out )
300+ else
301+ seq.int(r1 $ year , as.POSIXlt(to )$ year , by )
310302 res <- as.Date(r1 )
311303 } else { # months or quarters
312- if (valid == 4L ) by <- by * 3
313- if (missing( to )) {
314- mon <- seq.int( r1 $ mon , by = by , length.out = length.out )
315- } else {
316- to0 <- as.POSIXlt( to )
317- mon <- seq.int( r1 $ mon , 12 * ( to0 $ year - r1 $ year ) + to0 $ mon , by )
318- }
319- r1 $ mon <- mon
304+ if (valid == 4L ) by <- by * 3L
305+ r1 $ mon <-
306+ if (missing( to ) )
307+ seq.int( r1 $ mon , by = by , length.out = length.out )
308+ else {
309+ to0 <- as.POSIXlt( to )
310+ seq.int( r1 $ mon , 12L * ( to0 $ year - r1 $ year ) + to0 $ mon , by )
311+ }
320312 res <- as.Date(r1 )
321313 }
322314 }
0 commit comments