joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

.parseISO8601() if statement may have length > 1 logical #280

Closed joshuaulrich closed 5 years ago

joshuaulrich commented 5 years ago

Thanks to Kurt Hornik for this report! xts will fail R CMD check on recent R-devel if run with: _R_CHECK_LENGTH_1_LOGIC2_=package:_R_CHECK_PACKAGE_NAME_,abort,verbose

The lines that triggers the error is in test.i_invalid_date_string():

x <- xts(1:10, as.Date("2015-02-20")+0:9)
y <- x["2015-02-30"]  # error triggered in .parseISO8601() called here

The specific line in .parseISO8601() is: if(is.na(s) && is.na(e) && !nzchar(DURATION) && intervals != "").

This is because intervals is only length-1 and equal to "" when [.xts is called with a value for i that is only a separator (e.g. "/" or "::").

The printed values after each call are some examples of the values of intervals during different subset calls:

R> y <- x["/",]
[1] ""
R> y <- x["/2015",]
[1] ""     "2015"
R> y <- x["2015/",]
[1] "2015"
R> y <- x["2015-02-28",]
[1] "2015-02-28" "2015-02-28"
R> y <- x["2015-02-30",]
[1] "2015-02-30" "2015-02-30"