daattali / timevis

📅 Create interactive timeline visualizations in R
http://daattali.com/shiny/timevis-demo/
Other
655 stars 157 forks source link

Can't use tibbles #53

Closed muschellij2 closed 6 years ago

muschellij2 commented 6 years ago

Trying to use a tibble versus a data.frame causes errors:

library(timevis) # daattali/timevis
library(tibble)
data <- tibble::data_frame(
  id      = 1:4,
  content = c("Item one"  , "Item two"  ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA          ,           NA, "2016-02-04", NA)
)
timevis(data)
#> Error: Can't use matrix or array for column indexing

Created on 2018-04-02 by the reprex package (v0.2.0).

I think just adding a is.tibble then as.data.frame may help on line: https://github.com/daattali/timevis/blob/defb22873953d8b7f41c4212759d665732b4a5ff/R/utils.R#L20 which occurs because this returns TRUE because of tibble inheritance

You can also just do a simple:

if (is.data.frame(df)) {
    df = as.data.frame(df)
}
daattali commented 6 years ago

Thanks for the report. Feel free to submit a PR to convert tibbles to dataframes