-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Factor out eval_relocate()
and use dplyr_col_select()
in relocate()
#6342
Factor out eval_relocate()
and use dplyr_col_select()
in relocate()
#6342
Conversation
@lionel- would you mind looking at this since it would probably end up in tidyselect (r-lib/tidyselect#232)? I think it is ok if it is not 100% equivalent to what you'd implement for |
04d2b92
to
0224ecb
Compare
has_after <- !quo_is_null(.after) | ||
n <- length(data) | ||
|
||
before <- as_quosure(before, env = env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit on the fence about whether it'd be better to use enquo()
for these arguments. But it seems better to be consistent and only take strict arguments in an eval_
function, so I think this is a good solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I was trying to be consistent with expr
here, since eval_select()
captures expr
in the same way with this as_quosure()
idea.
I started with enquo()
but it felt really strange. This felt better to me
R/relocate.R
Outdated
} | ||
|
||
if (has_before) { | ||
# TODO: Use `allow_rename = FALSE`. https://github.com/r-lib/tidyselect/issues/225 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed in the dev version which I plan to release right before the dplyr release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this bug still exists :/ r-lib/tidyselect#221
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this to my list of issues to fix for the dplyr release.
5862246
to
b31a925
Compare
Closes #5829 (but we'd still need to move this to tidyselect)
Closes #6167
Closes #6341
This PR pulls
eval_relocate()
out ofrelocate.data.frame()
. The eventual goal would be to move this to tidyselect for other backends to use it (#5829) but this is a good first step.The
before
andafter
arguments ofeval_relocate()
take defused input, orNULL
, which feels right given thatexpr
works basically the same way.eval_relocate()
returns a named integer vector the same size asncol(data)
(important invariant) that describes how to rearrange the columns ofdata
. The names are normally the same as the original data, but renaming can happen inexpr
so it is possible for them to be different.I fixed a few edge case bugs in the implementation of
eval_relocate()
. Mainly around 0-col data frames and what happens when you supply.before
or.after
but they result in an empty selection.I've also started using
dplyr_col_select()
inrelocate.data.frame()
rather than just.data[pos]
. This solves #6341 and probably a few other consistency bugs sincedplyr_col_select()
has a few extra sanity checks in it.