For example,
myfunc <- function (arg1, u=1, ...){
print(arg1)
print(u)
}
myfunc(3,arg=4)
# [1] 4
# [1] 3
I didn't want to match arg to arg1, and the first argument appears to be pushed to u
. Are there any ways to avoid this behavior?
For example,
myfunc <- function (arg1, u=1, ...){
print(arg1)
print(u)
}
myfunc(3,arg=4)
# [1] 4
# [1] 3
I didn't want to match arg to arg1, and the first argument appears to be pushed to u
. Are there any ways to avoid this behavior?
This (brief) text explains the order of argument evaluation in R functions: https://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching
Also see @Richie Cotton's answer to Why does R use partial matching?
To your question, if you want no partial matching (e.g. to return an error if arg1 does not exist), you can create conditions where there are two partial matches. Take for example this edit to your function:
myfunc <- function (arg1, arg2=1, ...){
print(arg1)
print(arg2)
}
#returns error "argument 2 matches multiple formal arguments"
myfunc(3,arg=4)