Dan,
That's a bug in setdiff. I've fixed it in the development version of
lubridate at http://github.com/hadley/lubridate. Thank you for finding it.
setdiff *does* intend to trap the two interval result and return an error.
The part of the visit where Chris is *not* there would be
intersect(auckland, jsm).
Cheers,
Garrett
On Sun, Feb 9, 2014 at 12:26 PM, Dan Murphy <chiefmurphy@gmail.com> wrote:
> In the lubridate vignette
> (http://cran.r-project.org/web/packages/lubridate/vignettes/lubridate.html
> )
>
> setdiff(auckland, jsm)
>
> results in
>
> ## [1] 2011-06-04 12:00:00 NZST--2011-07-20 NZST
>
> But if Hadley's mentor had been called away earlier, say, July 31st,
> wouldn't the set difference have resulted in two intervals? lubridate
> shows one:
>
> > jsm <- interval(ymd(20110720, tz = "Pacific/Auckland"),
ymd(20110731, tz
> = "Pacific/Auckland"))
> > setdiff(auckland, jsm)
> [1] 2011-07-31 NZST--2011-07-20 NZST
>
> i.e., the jsm interval in a negative direction (!).
>
> That would not appear to be the intended meaning because the setMethod
> code for "setdiff" seems to want to trap the two interval result:
>
> if (length(makes2)) {
> stop(paste("Cases", makes2,
> "result in discontinuous intervals."))
> }
>
> but maybe I'm hastily misinterpreting the meaning of that check.
>
> Thanks in advance for clarification.
>
> - Dan
>
> PS: (For the setdiff illustration, shouldn't the vignette be asking
> "For what part of my visit will Chris *not* be there?")
>
[[alternative HTML version deleted]]