markfairbanks / tidytable

Tidy interface to 'data.table'
https://markfairbanks.github.io/tidytable/
Other
449 stars 33 forks source link

map() pluck function not working? #693

Closed docfleetwood closed 1 year ago

docfleetwood commented 1 year ago

I was recently trying the following code...

list1 <- list(l1 = list(a = 1:5, b = 1:10, c = 1:20, d = letters[1:5]), l2 = list(a = 11:15, b = 11:20, c= 11:30, d = letters[3:8]), l3 = list(a = 21:25, b = 21:30, c = 21:40, d = letters[6:11]))

list1 %>% map_dfc("b") %>% map_dbl(mean) %>% mean()

This works with the tidyverse. But using tidytable gives me the following error...

Error in get(x, envir = env, mode = "function") : object 'b' of mode 'function' was not found

I also tried it using the pluck() function - map_dfc(pluck("b")) but got the same error.

Is the pluck function not implemented in tidytable map function?

Thank you for all the hard work!

markfairbanks commented 1 year ago

Ah interesting - I didn't know that pluck() functionality worked in map(), so this isn't built into tidytable::map(). pluck() itself isn't implemented in tidytable either.

In general I've decided not to add any more purrr functions to tidytable, so for more complicated use cases (like using pluck()) I would just recommend using purrr. There are a lot of purrr helpers, so it's a pretty slippery slope if I start adding more. In hindsight I'm not positive I would have added map() and just focused on dplyr/tidyr functionality, but it's been exported for so long it's going to stay.

But I'll have to think about this one. It still might be worth adding this functionality to tidytable::map().

docfleetwood commented 1 year ago

Thank you for the information, that is good to know.

Have a great day!

On Mon, Nov 14, 2022 at 9:29 PM Mark Fairbanks @.***> wrote:

Ah interesting! I didn't know that pluck() functionality worked in map(), so this isn't built into tidytable::map(). pluck() itself isn't implemented in tidytable either.

In general I've decided not to add any more purrr functions to tidytable, so for more complicated use cases (like using pluck()) I would just recommend using purrr. There are a lot of purrr helpers, so it's a pretty slippery slope if I start adding more. In hindsight I'm not positive I would have added map() and just focused on dplyr/tidyr functionality, but it's been exported for so long it's going to stay.

But I'll have to think about this one. It still might be worth adding this functionality to tidytable::map().

— Reply to this email directly, view it on GitHub https://github.com/markfairbanks/tidytable/issues/693#issuecomment-1314675334, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP7VBNVVHERQTMGDOGEDDP3WILYRXANCNFSM6AAAAAASALJ4OU . You are receiving this because you authored the thread.Message ID: @.***>

markfairbanks commented 1 year ago

@docfleetwood - I think I'm going to keep this functionality out of tidytable per the reasoning from https://github.com/markfairbanks/tidytable/issues/693#issuecomment-1314675334.

If you run into any dplyr/tidyr functionality that is missing let me know 😄