haleyjeppson/ggmosaic

Avoid exporting as_tibble.list

jennybc opened this issue · 1 comments

I have a bug report on readxl that I believe originates in the as_tibble.list() method exported here (tidyverse/readxl#482).

as_tibble.list <- function(x, ...) {
#cat("as.tibble.list \n")
# still need to check that we are not accidentally hijacking a real list vector
# this is why we got called:
if (length(x) == 0) {
return(getFromNamespace("as_tibble.list", asNamespace("tibble"))(x))
}
idx <- which(sapply(x, function(xx) "tbl_df" %in% class(xx)))
if (length(idx) == 0) {
return(getFromNamespace("as_tibble.list", asNamespace("tibble"))(x))
}
if (! any(sapply(x[idx], function(xx) "productlist" %in% class(xx[[1]])))) {
dx <- getFromNamespace("as_tibble.list", asNamespace("tibble"))(x)
return(dx)
}

Unfortunately, I can't reproduce the OP's issue because he did not provide his test.xlsx file. But the spreadsheet must have some combination of missing/duplicated columns that creates a list that is an edge case for your code intended to "not accidentally hijack a real list vector".

I don't understand this package well enough to know why you have as_tibble.list(). But I think it's not a good practice to export a method (a list method, in this case) that masks a method provided by the package that owns the generic (as_tibble() and the tibble package, in this case).

Can you create an S3 class for whatever list-y output you need special handling for (e.g. mosaic_list) and create an as_tibble() method for that instead (e.g. as_tibble.mosaic_list)?

This issue has been fixed (a big thank you to @earowang !!) and we are no longer hijacking as_tibble.list()