This bug happens when working with lubridate + dplyr. If a data.frame contains some period object of length 0s, and also some other non-date column, distinct() actually rearranges the rows in each column, creating erroneous data.
library(lubridate) library(dplyr) time_fruit <- data_frame(x = hm("10:30", "10:30", "14:40"), y = c("apple", "apple", "banana")) time_fruit #> # A tibble: 3 × 2 #> x y #> <S4: Period> <chr> #> 1 10H 30M 0S apple #> 2 10H 30M 0S apple #> 3 14H 40M 0S banana distinct(time_fruit) #> # A tibble: 2 × 2 #> x y #> <S4: Period> <chr> #> 1 10H 30M 0S apple #> 2 10H 30M 0S banana time_fruit2 <- data_frame(x = hm("10:30", "10:30", "14:40", "0:0"), y = c("apple", "apple", "banana", "tomato")) time_fruit2 #> # A tibble: 4 × 2 #> x y #> <S4: Period> <chr> #> 1 10H 30M 0S apple #> 2 10H 30M 0S apple #> 3 14H 40M 0S banana #> 4 0S tomato distinct(time_fruit2) #> # A tibble: 3 × 2 #> x y #> <S4: Period> <chr> #> 1 10H 30M 0S apple #> 2 10H 30M 0S banana #> 3 14H 40M 0S tomato
devtools::session_info() #> Session info -------------------------------------------------------------- #> setting value #> version R version 3.3.2 (2016-10-31) #> system x86_64, darwin13.4.0 #> ui X11 #> language (EN) #> collate en_CA.UTF-8 #> tz Europe/Paris #> date 2017-03-24 #> Packages ------------------------------------------------------------------ #> package * version date source #> assertthat 0.1 2013-12-06 CRAN (R 3.3.0) #> backports 1.0.5 2017-01-18 CRAN (R 3.3.2) #> DBI 0.6 2017-03-09 cran (@0.6) #> devtools 1.12.0 2016-06-24 CRAN (R 3.3.0) #> digest 0.6.12 2017-01-27 cran (@0.6.12) #> dplyr * 0.5.0 2016-06-24 CRAN (R 3.3.0) #> evaluate 0.10 2016-10-11 cran (@0.10) #> htmltools 0.3.5 2016-03-21 CRAN (R 3.3.0) #> knitr 1.15.1 2016-11-22 cran (@1.15.1) #> lazyeval 0.2.0 2016-06-12 CRAN (R 3.3.0) #> lubridate * 1.6.0 2016-09-13 CRAN (R 3.3.0) #> magrittr 1.5 2014-11-22 CRAN (R 3.3.0) #> memoise 1.0.0 2016-01-29 CRAN (R 3.3.0) #> R6 2.2.0 2016-10-05 cran (@2.2.0) #> Rcpp 0.12.10 2017-03-21 Github (RcppCore/Rcpp@5a71cf6) #> rmarkdown 1.3 2016-12-21 cran (@1.3) #> rprojroot 1.2 2017-01-16 CRAN (R 3.3.2) #> stringi 1.1.2 2016-10-01 cran (@1.1.2) #> stringr 1.2.0 2017-02-18 cran (@1.2.0) #> tibble 1.2 2016-08-26 CRAN (R 3.3.0) #> withr 1.0.2 2016-06-20 CRAN (R 3.3.0) #> yaml 2.1.14 2016-11-12 cran (@2.1.14)