This code :
f1 <- function(abc , ac , df){
list(f1 = abc , f2=ac , f3 = df)
}
f1(1,2,a=3)
returns error :
Error in f1(1, 2, a = 3) : argument 3 matches multiple formal arguments
Is reason for this error a is being matched by arguments abc
, ac
in function f1
due to function partial matching
?
When a named argument doesn't match exactly any formal arguments,
R tries to apply partial matching by prefix.
abc
and ac
both start with "a",
and R doesn't know which one it should use,
so it raises an error.
If you use f1(1, 2, ac=3)
,
then R will assign 3
to ac
,
and then it will assign the remaining values to the remaining unassigned parameters,
so 1
to abc
and 2
to df
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With