Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
[.xts returns all data when i is not a valid date/time #96
R> x <- xts(1:10, as.Date("2015-02-20")+0:9) R> x['2012-02-30'] [,1] 2015-02-20 1 2015-02-21 2 2015-02-22 3 2015-02-23 4 2015-02-24 5 2015-02-25 6 2015-02-26 7 2015-02-27 8 2015-02-28 9 2015-03-01 10
I thought the issue occured in/around lines 107-126 of
But Jeff suggested that the fix should stay out of
Thanks to Garrett See for the report.
This makes me lean toward having the window function that I was proposing, have a base function that returns indexes. Essentially, subsetting with window should behave the same as subsetting with . The idea would be to have subset process the range strings (as applicable) and call window_return_indexes. One wrinkle here is that the window.zoo function says that if start = NULL, this is interpreted as no constraint on the start date. (And similarly with end).
I should clarify here. The point is not that window is automatically smarter (though it might help to have an NA check). The big point is there are some ambiguous cases - like what happens with an NA date - where reasonable people might disagree on the answer. Anyway - whatever standard is picked in subset for a range, I should make sure I follow it - and it may not be obvious. This says to me that I should make the effort to create a base window method that can be reused by subset to ensure consistency. So it means more work for me but is probably the right thing to do.
This will cause a failure in 'R CMD check' in R-3.6.0. This was introduced in 16bed0f as part of #96 (prevent subset from returning all data when 'i' is not a valid date- time). This should only be an issue when 'intervals' is length-1 and the first 3 logical comparisons are TRUE. So we only need to check whether the first element of 'intervals' is an empty string. Also add unit tests for basic functionality, and add some fuzz tests too. Fixes #280.