Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upOdd 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
setnameswith 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 allowingoldto be missing, sonewcan be set by name instead.