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
pivot_wider()
with id_cols
of length 0 and unused_fn
#698
Comments
Interesting - I wasn't aware of this functionality.
Yeah if you want to take a shot at this feel free to. I think this is the general approach we need. But let me know if I'm missing anything. Also - this is sort of pseudo-code below, I don't know if this is exactly how it will work. Once
For part 2 - wouldn't we basically just need something like this? (Probably with a conditional if statement) unused_df <- select(.df, all_of(id_cols), all_of(unused_cols))
unused_df <- summarize(unused_df, across(all_of(unused_cols), unused_fn), .by = all_of(id_cols))
out <- bind_cols(out, unused_df)
# And maybe a relocate step to have the correct column order? Or maybe select?
# out <- select(out, all_of(id_cols), all_of(unused_cols), everything()) |
I think my approach with tidyverse sometimes relies on a lesser-known functionality, as you can see by my issues, haha. I will look into this, yeah! Sounds about right with that approach, I will have to think about how to identify BTW, I think its also a good idea to port some tests over from tidyverse and look for missing / non-matching / broken functionality between packages. |
All set - sorry this one took so long to get to! library(tidytable)
df <- data.frame(
a = LETTERS[1:2],
b = LETTERS[3:4],
val = 1:2
)
df %>%
pivot_wider(
id_cols = character(0),
names_from = a,
values_from = val
)
#> # A tidytable: 1 × 2
#> A B
#> <int> <int>
#> 1 1 2 |
Currently specifying
character(0)
/numeric(0)
inid_cols
leads to behavior similar toNULL
(the default), but also produces a warning:Created on 2022-11-29 with reprex v2.0.2
{tidyr}
handles it differently. They apply function passed in the argumentunused_fn
(default is to omit columns) to all columns not mentioned inid_cols
,names_from
, orvalues_from
, which leads to this:Created on 2022-11-29 with reprex v2.0.2
Another note: with
NULL
inid_cols
,{tidyr}
considers all columns not mentioned bynames_from
, orvalues_from
asid_cols
, which affectsid_expand
(currently also not implemented, but a thing to keep in mind for future).I can tackle this if you want, though this may lead to a rather big change in how
pivot_wider()
is coded 😅The text was updated successfully, but these errors were encountered: