Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as_dm() accepts non-dataframe objects which can lead to unexpected errors #2197

Open
DanChaltiel opened this issue Feb 21, 2024 · 1 comment

Comments

@DanChaltiel
Copy link

Hi,

I recently discovered this great package, thank you very much for your work!

I'm working with a package that outputs a list of dataframe from a database.
However, the list also contains some metadata members of various types along with the dataframes.
Using as_dm() on the list throws no warning regarding those members and their presence causes some bugs in functions such as dm_draw().

Here is a reprex:

library(dm)
a = list(a=iris, b=mtcars, x=1)
x = as_dm(a)
x
#> -- Metadata --------------------------------------------------------------------
#> Tables: `a`, `b`, `x`
#> Columns: 16
#> Primary keys: 0
#> Foreign keys: 0

dm_draw(x, rankdir = "TB", view_type = "all")
#> Error in `vec_rbind()`:
#> ! Can't combine `..1$column` <character> and `..3$column` <logical>.

Created on 2024-02-21 with reprex v2.0.2

Note that x is considered as a table in the printed Metadata.

The error points to unnest.R#L47, and is caused by non-dataframes yielding a logical (and empty) column column in col_data.

I would expect either an early error in as_dm() forbidding the list to contain any non-dataframe, or an automatic removal of non-dataframes, maybe with a warning.
A hint to use purr::keep(my_list, is.data.frame) might be useful too.

I'd be happy to provide a PR if that can help you.

@krlmlr
Copy link
Collaborator

krlmlr commented Nov 24, 2024

Thanks, I agree we should be testing inputs more carefully here. Would you like to contribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants