-
Notifications
You must be signed in to change notification settings - Fork 2.1k
pull() can also return named vectors #4102
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
pull() can also return named vectors #4102
Conversation
Adding a new parameter to a generic is technically a breaking API change (since it may cause CRAN packages to fail) so we'll need to carefully consider it. I think the basic idea is fine, but I'd called the new argument |
Thanks for the feedback. I didn't realize it counted as a breaking change. As it's just a small shortcut, I'm not sure if it's worth the pain then. For what it's worth, I changed the default to |
Do we have a way to check if dependent packages define their own method for |
We already have |
That's kind of a stretch @krlmlr ? |
I'm currently in the middle of a
So, at least (I didn't know about |
Is it? I thought, functions should do one thing and do it well. |
Here are the cases I identified among the 1,500 packages
https://gitlab.com/msberends/AMR/blob/master/R/atc.R
https://github.com/tidyverse/dbplyr/blob/master/R/verb-pull.R
https://github.com/metrumresearchgroup/mrgsolve/blob/master/R/mrgsims.R
https://github.com/thomasp85/tidygraph/blob/master/R/pull.R Full output
|
Thanks for the detailed analysis. It would not be a lot of packages to amend. It's essentially a case of "do we want that now" @hadley |
I think we can merge in 0.9.0 |
I'd like to propose the following course of action:
|
I'd rather keep |
This PR implements an additional parameter for
pull()
that lets one return named vectors.Essentially, it is a shorthand so that instead of this:
One can write:
If one specifies only one variable, the behaviour is exactly the same as before. But if there is a second variable, it is used for the names of the returned vector.
Created on 2019-01-11 by the reprex package (v0.2.1)
Basic tests for the new functionality are included.
I didn't set a default value for the new parameter
namevar
, and check if it ismissing()
. But I also pondered if a more fitting pair for the default value ofvar = -1
could benamevar = 0
for the unnamed case, and I'm happy to change it to that if you like that one better.As the PR is quite small, I haven't filed an issue, but happy to do that if it's preferred. The contributing instructions tell to do it for "substantial" PRs, but this felt so simple I went straight for the implementation.
I didn't yet make any changes to
NEWS
(orDESCRIPTION
) as in branch master they are still at 0.8.0 for the upcoming release. I'm happy to add to this PR later to add an item toNEWS
, but thought I'd leave it out for now to not cause any extra work for maintainers, in case a number of PRs go about bumping the version number and adding a new header toNEWS
.