CompoundDb
CompoundDb copied to clipboard
Create collapse_table, expand_table functions
Create functions that allow to collapse or expand a data.frame keeping unique values in some columns and list of elements in the other.
Collapsing a data.frame turns out to be quite simple, but expanding it is tricky.
I think I am looking for something similar in the database. It is basically a generalize way to do the synonyms nested column right?
My use case is that I have a list of compounds but only their name and CAS. I will retrieve the structure from databases but I get multiple hits for each CAS. So I want to save the possible structures and curate them from there.
I think you could use
df %>% tidyr::chop(-A)
instead of .collapse_table.
Unnesting can be done with tidyr::unchop(-A).
Alternative there is also df %>% tidyr::nest(data = -A) that keeps A unique and nests all the rest on one data.frame.
Thanks. I will look into this.