Prevent partial argument matching
r
Solution
Here's an idea:
myFunc <- function(x, .BASE = '', ..., base = .BASE) {
base
}
## Takes fully matching named arguments
myFunc(x = "somevalue", base = "someothervalue")
# [1] "someothervalue"
## Positional matching works
myFunc("somevalue", "someothervalue")
# [1] "someothervalue"
## Partial matching _doesn't_ work, as desired
myFunc("somevalue", b="someothervalue")
# [1] ""
Problem
I have an R function: ``` myFunc <- function(x, base='') { } ``` I am now extending the function, allowing a set of arbitrary extra arguments: ``` myFunc <- function(x, base='', ...) { } ``` How may I disable partial argument matching on the `base` parameter? I cannot put the `...` before `base=''` because I'd like to maintain backwards compatibility of the function (it is often called as `myFunction('somevalue', 'someothervalue')` without `base` being explicitly named). I got stung by calling my function like so: ``` myFunc(x, b='foo') ``` I want this to mean `base='', b='foo'`, but R uses partial matching and assumes `base='foo'`. Is there some code I can insert in `myFunc` to determine what argument names were passed in and only match the exact "base" to the `base` parameter, otherwise grouping it in as part of the `...`?