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

Extract mutate_col() from mutate_cols() #6438

Merged
merged 2 commits into from
Sep 8, 2022
Merged

Extract mutate_col() from mutate_cols() #6438

merged 2 commits into from
Sep 8, 2022

Conversation

lionel-
Copy link
Member

@lionel- lionel- commented Aug 30, 2022

This PR extracts the body of the mutate_cols() loop into a separate function. This simplifies the withCallingHandlers() call and it is easier to see what's going on in the handled expression and in the condition handlers. Also reduces nesting/indentation inside the body, making it easier to read.

Copy link
Member

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, will probably make debugging in the IDE a little easier too

R/mutate.R Outdated
Comment on lines 237 to 238
context_poke("column", old_current_column)
new_columns <- mutate_col(i, .data, dots, mask, new_columns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you could do

dot <- dots[[I]]
new_columns <- mutate_col(.data, dot, mask, new_columns)

That would really narrow the scope (i.e. mutate_col() doesn't need to know which iteration it is on, and it doesn't need all the dots, only the one it currently has to process)

It seems like you didn't change much code while extracting this out, which I appreciate because it made it easier to review 😄 but this might be worth it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops good catch, somehow I thought the function depended on its iteration number.

@lionel- lionel- force-pushed the simplify-mutate-cols branch from 14688d9 to ff7bdfb Compare September 8, 2022 09:25
@lionel- lionel- merged commit 5f967b4 into main Sep 8, 2022
@lionel- lionel- deleted the simplify-mutate-cols branch September 8, 2022 09:35
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