nathaneastwood / poorman

A poor man's dependency free grammar of data manipulation
https://nathaneastwood.github.io/poorman/
Other
338 stars 15 forks source link

Add pivot_wider() #47

Closed nathaneastwood closed 2 years ago

bwiernik commented 3 years ago

The datawizard package has adaptations for much of the pivot_*() functionality via wrappers around reshape(). This could be a place to start: https://github.com/easystats/datawizard/blob/master/R/data_reshape.R

nathaneastwood commented 3 years ago

Thanks @bwiernik! This is exactly what I was looking to do. I have some partial scripts for this functionality myself and had originally hoped to have a student do this for the Google Summer of Code project but it fell through. I will take another look as it has been a while.

bwiernik commented 3 years ago

No problem! Not all of the functionality is there yet and in particular select helpers aren't there yet https://github.com/easystats/datawizard/issues/15

etiennebacher commented 2 years ago

@nathaneastwood in case you're still interested, there were some improvements in datawizard's reshape_longer and reshape_wider to match more accurately the pivot_ functions and arguments. Not all args are implemented yet, and it uses some datawizard internal functions and select helpers, but I'm sure you could replace them by your functions and select helpers

nathaneastwood commented 2 years ago

Sounds great @etiennebacher, thanks for letting me know. At some point I will get around to this...

nathaneastwood commented 2 years ago

It was suggested by @grantmcdermott to make use of stack() and unstack() for the pivot_() functions. I like this suggestion but I will take a look at how you do it in datawizard too.

etiennebacher commented 2 years ago

Yes I saw this suggestion in the other issue and it looks really interesting, I never heard of stack and unstack before. I remember trying to use them for datawizard but 1) there is not much documentation for these functions 2) I found virtually no previous questions on stackoverflow or blog posts and 3) even if it works for basic examples, I remember feeling stuck quite fast when I needed to add other pivot arguments.

Maybe I didn't try hard enough and if you manage to use them, I would be really interested to see how you do it. The code in datawizard mimics quite well the pivot functions, but I must say the way stats::reshape works remains quite mysterious to me (it was a lot of trials and errors to get the output needed). In case it helps, I took a quick look at how to implement datawizard functions in poorman and found that you can replace the .select_nse lines with cols <- names(eval_select_pos(data, substitute(cols))) in reshape_longer. If you don't have time at all for this, I can probably make a PR in the coming weeks.

nathaneastwood commented 2 years ago

I feel your pain, I know I have a lot of sample code for these pivot_ functions from a lot of trial and error I also did. Which is probably why I ended up putting it to one side at the time.

My schedule is supposed to be clearing up a little over the next month so hopefully I can find some free time however I wouldn't be against a PR of course.

grantmcdermott commented 2 years ago

Yeah, just adding my :-\ face about base reshape. It was clearly designed for such a singular use-case that adapting it is a real PITA. I still do like (un)stack a lot, though as per #48.