Bug 17342 - seq.POSIXt(by="n DSTdays", ...) for large n can give answer padded with many NAs
Summary: seq.POSIXt(by="n DSTdays", ...) for large n can give answer padded with many NAs
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: R 3.4.1
Hardware: Other Other
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-09-21 18:10 UTC by Bill Dunlap
Modified: 2017-09-23 07:06 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2017-09-21 18:10:17 UTC
seq.POSIXt gives bad results when using by="n DSTdays" with a fairly large value of 'n'.

E.g., I expect the following to get a vector of 13 equally spaced times but R-3.4.1 and R-devel given those times plus 1789 NAs.

> x <- seq(as.POSIXct("1982-04-15 05:00", tz="US/Central"), as.POSIXct("1994-10-15", tz="US/Central"), by="360 DSTdays")
> str(x, vec.len=20)
 POSIXct[1:1802], format: "1982-04-15 05:00:00" "1983-04-10 05:00:00" "1984-04-04 05:00:00" "1985-03-30 05:00:00" "1986-03-25 05:00:00" "1987-03-20 05:00:00" "1988-03-14 05:00:00" "1989-03-09 05:00:00" "1990-03-04 05:00:00" "1991-02-27 05:00:00" "1992-02-22 05:00:00" "1993-02-16 05:00:00" "1994-02-11 05:00:00" NA NA NA NA NA NA NA ...
> table(is.na(x))

FALSE  TRUE
   13  1789

A less extreme example is

> seq(as.POSIXct("1982-04-15 05:00", tz="US/Central"), as.POSIXct("1989-10-15 05:00", tz="US/Central"), by="366 DSTdays")
 [1] "1982-04-15 05:00:00 CST" "1983-04-16 05:00:00 CST"
 [3] "1984-04-16 05:00:00 CST" "1985-04-17 05:00:00 CST"
 [5] "1986-04-18 05:00:00 CST" "1987-04-19 05:00:00 CDT"
 [7] "1988-04-19 05:00:00 CDT" "1989-04-20 05:00:00 CDT"
 [9] NA                        NA
[11] NA                        NA
[13] NA                        NA
[15] NA                        NA
Comment 1 Bill Dunlap 2017-09-21 18:24:16 UTC
I forgot to include the sessionInfo().  I see the same results on Windows and Linux versions of R-3.4.1 and Linux R-devel r73321.

> sessionInfo()
R Under development (unstable) (2017-09-19 r73321)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/libf77blas.so.3.0
LAPACK: /home/R/R-devel/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.5.0
Comment 2 Martin Maechler 2017-09-22 13:03:22 UTC
The good news is that it is not a new bug. Found in half a dozen R versions going back up to 2.0.1
Comment 3 Martin Maechler 2017-09-23 07:06:12 UTC
There's been a thinko in that code ... which did not always show, because of a subsequent limitation into the correct range.

Fix committed to R-devel only -- as R 3.4.2 has already been in code freeze state.