Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%within% failed inelegantly when a non interval argument is presented #829

Closed
aetiologicCanada opened this issue Nov 22, 2019 · 2 comments
Labels

Comments

@aetiologicCanada
Copy link

@aetiologicCanada aetiologicCanada commented Nov 22, 2019

%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
%within% should fail or at least report when class(var2)~= interval

@hadley

This comment has been minimized.

Copy link
Member

@hadley hadley commented Nov 27, 2019

Can you please provide a minimal reproducible example using the reprex package? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it. If you've never made a minimal reprex before, there is lots of good advice here.

@hadley hadley added the reprex label Nov 27, 2019
@vspinu vspinu closed this in 5ef92c9 Nov 30, 2019
@vspinu

This comment has been minimized.

Copy link
Member

@vspinu vspinu commented Nov 30, 2019

It's actually R problem. We don't provide the default method so It throws before it even gets to our code. Fixing this by adding a default method with an explicit message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.