Open ctbrown opened 6 years ago
@ctbrown A quick fix could be as simple as including the following as the first line within the function:
data <- as.data.frame(data)
If the tibble structure is purely about presentation/formatting when printing and there is nothing else that gets lost when converting to a data frame, then this solution should work fine.
I haven't looked at this in depth, but I don't understand why it is failing since tibbles are a subclass of data.frame:
> data(iris)
> tbl <- as_tibble(iris)
> class(tbl)
[1] "tbl_df" "tbl" "data.frame"
> is.data.frame(tbl)
[1] TRUE
There might just be something else going on here.
I just ran across this RStudio blog post about tibbles. The "Tibbles vs. data frames" section seems relevant, especially the section on subsetting.
Looks like in line 31 of your code, a data frame with single bracket notation will return a vector but a tibble will return a data frame (and will ignore drop = TRUE
even if specified). I did a quick test and changing class(data[,nm])
to class(data[[nm]])
seems to work just fine as an alternative fix to what I proposed.
In the last section of the blog post ("Interacting with legacy code"), it's noted that turning a tibble back into a data frame using as.data.frame()
works with legacy code. Either option should work here.
From Ryan Brellenthin (via email)