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

Ability to specify lists, Not lists, colon, or nothing for @pivot_longer #104

Merged
merged 6 commits into from
Jun 9, 2024

Conversation

cnrrobertson
Copy link
Contributor

@cnrrobertson cnrrobertson commented May 23, 2024

This will allow things like:

@pivot_longer(df, [col1, col5])

or

@pivot_longer(df, -[col1, col5])

and my favorites:

@pivot_longer(df, :)

and

@pivot_longer(df) # Equivalent to :

This is not consistent with the tidyr syntax which would be pivot_longer(df, cols=everything()) but I think it's more ergonomic and Julian. Let me know if you think it should be more tidyverse-esque.

Addresses #10.

@kdpsingh
Copy link
Member

Appreciate your work on this @cnrrobertson! Have a tight deadline on another project so will look at this in 2 weeks.

In general, my philosophy is that the syntax should look like tidyverse. We include an everything() function in TidierData which is merely an alias for All(). I'm curious to see how the multi-negated selection is implemented. Will take a look and share feedback.

@cnrrobertson
Copy link
Contributor Author

Aha! I had no idea about everything(). I actually authored this PR just to try to solve that very issue. Should have asked on Slack first..

Either way, please look it over whenever you have time. I'm fairly new to macro programming, but these were actually very straightforward implementations. Basically just grabbing vectors or negated vectors in @capture.

I should mention that this is currently limited and won't work for things like: @pivot_longer(df, [col1, col10:col12]).

I have also worked on an implementation that would allow splatted names like @pivot_longer(df, col1, col3, col5) but it gets tricky with arbitrary combinations like @pivot_longer(df, col1, col7:col8). Let me know if this is a direction you would like to pursue.

@kdpsingh
Copy link
Member

kdpsingh commented Jun 8, 2024

Thank you again for working on this. This is great! There are a few edge cases I need to fix with the negated selection and then I will merge.

…olumns. Prefixing tuples/vectors with a `-` or `!` will exclude the selected columns. Updated docs to use `Cols()` for column interpolation.
@kdpsingh
Copy link
Member

kdpsingh commented Jun 9, 2024

I should mention that this is currently limited and won't work for things like: @pivot_longer(df, [col1, col10:col12]).

It does now!

@kdpsingh kdpsingh merged commit 7f1ac79 into TidierOrg:main Jun 9, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants