Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
%within% fails inelegantly when given a non interval second argument,
library(lubridate) date1 <- lubridate::ymd("2019-01-01") date2 <- lubridate::ymd("2020-01-01") # typo folllows: date_range <- lubridate::ymd(date1, date2) # this should have read: # date_range <- lubridate::interval(date1, date2) # but ymd appropriately just runs over the two dates and products a vector in date_range. # sensible enough, even appropriate, but unfortunately # date_range as a vector of 2 dates looks very much like # date_range as an interval # when you print them, and it is easy (trust me, there is an hour of my life missing because of this) # to miss that little detail.... # if date_range is a vector of dates then lubridate::ymd("2019-06-01") %within% date_range # fails cryptically with: # Error in .setupMethodsTables(fdef, initialize = TRUE) : # no slot of name "group" for this object of class "derivedDefaultMethod" # I suggest %within% should test if the interval component of function is truly an interval. # There is no reason for it to accept a date or other class of object # %within% works fine when e.g. date1=date2 # no clear need for %within% to allow a date or other class as interval argument # %wtihin% also allows and fails cryptically for use cases such as: lubridate::ymd("2019-06-01") %within% 5 lubridate::ymd("2019-06-01") %within% "A"
So, the request is that %wtihin% test and report when call is something llike e.g. var1 %wtihin% var2