tidyverse / tidyr

Tidy Messy Data
https://tidyr.tidyverse.org/
Other
1.39k stars 420 forks source link

Extra class name can cause NA output #466

Closed esppk closed 6 years ago

esppk commented 6 years ago

Say I have a df with extra class names: class(df_err) #"frequency" "textstat" "data.frame" df_err #feature frequency #one_of 1387
#a_lot 1091

Then use seperate or extract will cause frequency return NA df_err %>% separate(feature, c("V1","V2")) V1 V2 feature frequency one of NA NA a lot NA NA following code will work fine: df_err %>% as.data.frame() %>% separate(feature, c("V1","V2")) V1 V2 frequency one of 1387 a lot 1091

rbloehm commented 6 years ago

Could you maybe give a fully reproducible example? Using latest R and tidyverse (see session info) I cannot reproduce this right now:

library(tidyr)
df_err <- data.frame(feature = c("one_of", "a_lot"),
                     frequency = c(1387, 1091),
                     stringsAsFactors = F)
class(df_err) <- c("frequency", "textstat", "data.frame")

class(df_err)
#> [1] "frequency"  "textstat"   "data.frame"
df_err
#>   feature frequency
#> 1  one_of      1387
#> 2   a_lot      1091

df_err %>% separate(feature, c("V1","V2"))
#>    V1  V2 frequency
#> 1 one  of      1387
#> 2   a lot      1091
Session info ``` r devtools::session_info() #> Session info ------------------------------------------------------------- #> setting value #> version R version 3.5.0 (2018-04-23) #> system x86_64, darwin15.6.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> tz Europe/Berlin #> date 2018-06-17 #> Packages ----------------------------------------------------------------- #> package * version date source #> assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0) #> backports 1.1.2 2017-12-13 CRAN (R 3.5.0) #> base * 3.5.0 2018-04-24 local #> bindr 0.1.1 2018-03-13 CRAN (R 3.5.0) #> bindrcpp 0.2.2 2018-03-29 CRAN (R 3.5.0) #> compiler 3.5.0 2018-04-24 local #> datasets * 3.5.0 2018-04-24 local #> devtools 1.13.5 2018-02-18 CRAN (R 3.5.0) #> digest 0.6.15 2018-01-28 CRAN (R 3.5.0) #> dplyr 0.7.5 2018-05-19 CRAN (R 3.5.0) #> evaluate 0.10.1 2017-06-24 CRAN (R 3.5.0) #> glue 1.2.0 2017-10-29 CRAN (R 3.5.0) #> graphics * 3.5.0 2018-04-24 local #> grDevices * 3.5.0 2018-04-24 local #> htmltools 0.3.6 2017-04-28 CRAN (R 3.5.0) #> knitr 1.20 2018-02-20 CRAN (R 3.5.0) #> magrittr 1.5 2014-11-22 CRAN (R 3.5.0) #> memoise 1.1.0 2017-04-21 CRAN (R 3.5.0) #> methods * 3.5.0 2018-04-24 local #> pillar 1.2.3 2018-05-25 CRAN (R 3.5.0) #> pkgconfig 2.0.1 2017-03-21 CRAN (R 3.5.0) #> purrr 0.2.5 2018-05-29 CRAN (R 3.5.0) #> R6 2.2.2 2017-06-17 CRAN (R 3.5.0) #> Rcpp 0.12.17 2018-05-18 CRAN (R 3.5.0) #> rlang 0.2.1 2018-05-30 CRAN (R 3.5.0) #> rmarkdown 1.10 2018-06-11 CRAN (R 3.5.0) #> rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.0) #> stats * 3.5.0 2018-04-24 local #> stringi 1.2.3 2018-06-12 cran (@1.2.3) #> stringr 1.3.1 2018-05-10 CRAN (R 3.5.0) #> tibble 1.4.2 2018-01-22 CRAN (R 3.5.0) #> tidyr * 0.8.1 2018-05-18 CRAN (R 3.5.0) #> tidyselect 0.2.4 2018-02-26 cran (@0.2.4) #> tools 3.5.0 2018-04-24 local #> utils * 3.5.0 2018-04-24 local #> withr 2.1.2 2018-03-15 CRAN (R 3.5.0) #> yaml 2.1.19 2018-05-01 CRAN (R 3.5.0) ```
esppk commented 6 years ago

Oh, sorry about that. Some misjudgment on my side. I just found out that the error starts to occur after loading following package. ( with exact code @rbloehm used )

library(quanteda) (quanteda web site)

Still think this behavior is kind of buggy, though not sure it's a tidyr's issue.