-
Notifications
You must be signed in to change notification settings - Fork 979
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
Odd parameter names of setnames
#4041
Comments
The goal of the current design is to allow both usages:
Unfortunately unless I'm missing something (very possible), that by necessity means the second argument will be overloaded -- in the first case, it's the new names; in the second case, it's the old names. We chose If you have an alternative in mind, that would be great. Or, if you explain what's wrong for your use case with using implicit argument matching, that would also be helpful. |
You should be able keep the existing overloading with an approach like the following. Keep the order and names of parameters as they are, but put this near the top of the definition of
This way, all existing code should work unaltered, and it will be possible to say |
but that's not the same. it requires naming 'new' explicitly, which will
break a mountain of code.
…On Wed, Nov 13, 2019, 2:33 AM Kodi Arfer ***@***.***> wrote:
You should be able keep the existing overloading with an approach like the
following. Keep the order and names of parameters as they are, but put this
near the top of the definition of setnames:
if (is.missing(old) && !is.missing(new)) {
old = new
new = NULL
}
This way, all existing code should work unaltered, and it will be possible
to say setnames(iris, new = LETTERS[1:6]).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4041?email_source=notifications&email_token=AB2BA5NINZHA3XDY5MYHFPTQTLZHTA5CNFSM4JMF26KKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED3LQ6I#issuecomment-553039993>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB2BA5PQQRHCIZOS3A4LFDLQTLZHTANCNFSM4JMF26KA>
.
|
I don't follow. Since the parameter order stays the same, |
maybe it's best to file a PR since it seems like you have something in mind already for how it would work. |
If you call
setnames
with just a vector of new names, then it looks likesetnames(df, c("date", "place", "value"))
, which is fine. But if you name the argument supplying the new names, then the call looks likesetnames(old = c("date", "place", "value"), df)
, which is confusing because you're supplying new names, not old ones. Consider allowingold
to be missing, sonew
can be set by name instead.The text was updated successfully, but these errors were encountered: