Skip to content

Feature request/clarification: %within% for vectors of intervals #658

@ghost

Description

%within% works wonderfully for the stated use case: a %within% b,
where a is a date/datetime, and b is an single interval.

But sometimes the user has a vector of intervals, even an unknown number of intervals, and the question is whether is: a %within% B, where B is a vector of intervals (b1, b2, b3...)

Example:given a set of reward blackout dates for a frequent-flyer program, can I book a flight that leaves at a particular time?

A very good solution is found here:

thanks to:https://stackoverflow.com/questions/28682816/match-dates-against-date-intervals-holiday-periods-in-multiple-years

If we assume that df$datetimes holds the flight times , and blackouts$interval holds the blackout intervals we wish to include/exclude, with one record per blackout period:

apply(sapply(df$datetime, function(x) x %within% blackouts$interval),2,any)

works just fine, but its a bit "ugly" in that way that R can be ugly.

So, two suggestions: 1) make explicit within the %within% documentation that %within%t does not work across a vector of intervals 2) perhaps offer a nice purr-ized example of the above for this specific and I suspect common situation.

As always, thanks, thanks and thanks again for the tidyverse!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions