Dplyr: Comportement étrange lors du filtrage de tibble contenant une colonne de lubrification

Créé le 11 juil. 2018  ·  3Commentaires  ·  Source: tidyverse/dplyr

Essayer de filtrer un tibble avec des colonnes lubrifiées peut entraîner un comportement étrange.

library(tidyverse)
library(tidyr)
library(lubridate)

htwd <- structure(list(code = c(10146L, 10252L, 10136L, 212L, 10252L, 
75L, 212L, 89L, 10134L, 349L), weekday = c(6, 6, 6, 6, 6, 6, 
6, 6, 6, 6), timedeb = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 
0), year = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), month = c(0, 0, 0, 
0, 0, 0, 0, 0, 0, 0), day = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), hour = c(8, 
11, 8, 22, 17, 19, 5, 3, 18, 22), minute = c(45, 0, 30, 15, 30, 
45, 45, 30, 15, 30), class = structure("Period", package = "lubridate"))), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"), .Names = c("code", 
"weekday", "timedeb"))

ftwd <- htwd %>% filter(code == 212)

ftwd$timedeb # This column has 10 elements (altough length(ftwd$timedeb) yields 3)
ftwd$code # This column has 3 elements
ftwd %>% mutate(x = weekday * period(day = 1) + timedeb) # As a result, this line yields an error

ftwd <- htwd[htwd$code == 212, ] # Good old subsetting gives the expected result
ftwd$timedeb
ftwd$code
ftwd %>% mutate(x = weekday * period(day = 1) + timedeb)

Commentaire le plus utile

Je pense que cela a déjà été "résolu" dans dplyr 0.7.6 en ajoutant un message d'erreur lorsque la colonne de filtrage et de lubrification est présente. Par résolu, je pense que cela signifie qu'il sera traité plus tard, dans le package vctrs. Pour l'instant, lubrifiez maintenant le support.

library(dplyr, warn.conflicts = FALSE)
packageVersion("dplyr")
#> [1] '0.7.6'

htwd <- structure(list(code = c(10146L, 10252L, 10136L, 212L, 10252L, 
                                75L, 212L, 89L, 10134L, 349L), weekday = c(6, 6, 6, 6, 6, 6, 
                                                                           6, 6, 6, 6), timedeb = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 
                                                                                                              0), year = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), month = c(0, 0, 0, 
                                                                                                                                                                    0, 0, 0, 0, 0, 0, 0), day = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), hour = c(8, 
                                                                                                                                                                                                                                          11, 8, 22, 17, 19, 5, 3, 18, 22), minute = c(45, 0, 30, 15, 30, 
                                                                                                                                                                                                                                                                                       45, 45, 30, 15, 30), class = structure("Period", package = "lubridate"))), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                -10L), class = c("tbl_df", "tbl", "data.frame"), .Names = c("code", 
                                                                                                                                                                                                                                                                                                                                                                                                                                            "weekday", "timedeb"))

htwd %>% 
  filter(code == 212)
#> Error in filter_impl(.data, quo): Column `timedeb` classes Period and Interval from lubridate are currently not supported.

Créé le 11/07/2018 par le package reprex (v0.2.0).

Tous les 3 commentaires

Je pense que cela a déjà été "résolu" dans dplyr 0.7.6 en ajoutant un message d'erreur lorsque la colonne de filtrage et de lubrification est présente. Par résolu, je pense que cela signifie qu'il sera traité plus tard, dans le package vctrs. Pour l'instant, lubrifiez maintenant le support.

library(dplyr, warn.conflicts = FALSE)
packageVersion("dplyr")
#> [1] '0.7.6'

htwd <- structure(list(code = c(10146L, 10252L, 10136L, 212L, 10252L, 
                                75L, 212L, 89L, 10134L, 349L), weekday = c(6, 6, 6, 6, 6, 6, 
                                                                           6, 6, 6, 6), timedeb = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 
                                                                                                              0), year = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), month = c(0, 0, 0, 
                                                                                                                                                                    0, 0, 0, 0, 0, 0, 0), day = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), hour = c(8, 
                                                                                                                                                                                                                                          11, 8, 22, 17, 19, 5, 3, 18, 22), minute = c(45, 0, 30, 15, 30, 
                                                                                                                                                                                                                                                                                       45, 45, 30, 15, 30), class = structure("Period", package = "lubridate"))), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                -10L), class = c("tbl_df", "tbl", "data.frame"), .Names = c("code", 
                                                                                                                                                                                                                                                                                                                                                                                                                                            "weekday", "timedeb"))

htwd %>% 
  filter(code == 212)
#> Error in filter_impl(.data, quo): Column `timedeb` classes Period and Interval from lubridate are currently not supported.

Créé le 11/07/2018 par le package reprex (v0.2.0).

Merci Christophe!

Cet ancien problème a été automatiquement verrouillé. Si vous pensez avoir trouvé un problème connexe, veuillez déposer un nouveau problème (avec reprex) et créer un lien vers ce problème. https://reprex.tidyverse.org/

Cette page vous a été utile?
0 / 5 - 0 notes