0

I wrote a simple function that takes a default argument and that also makes use of the ellipsis (...):

myFun <- function(resize = NULL, ...) {
    dots <- list(...)
    str(dots)
}

However, when I try to pass an argument that is similar to the default argument, it is not recognized:

> myFun(res = 1)
 list()
> myFun(resi = 2)
 list()

However, if I use a different name it works fine:

> myFun(abc = 2)
List of 1
 $ abc: num 2

> myFun(resize = 3, res = 1)
List of 1
 $ res: num 1

Is this behavior intended? If so, is there a proper way to deal with this issue (besides renaming arguments)?

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1    yaml_2.2.0  
mat
  • 2,412
  • 5
  • 31
  • 69
  • 2
    This seems helpful: [Partial matching of function argument](https://stackoverflow.com/questions/14153904/partial-matching-of-function-argument) – markus Aug 27 '18 at 08:26
  • 2
    "Is this behavior intended?" Yes, it is: https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Argument-matching – Roland Aug 27 '18 at 08:32

1 Answers1

0

This is intended behaviour, as stated in the R language definition. Function arguments are matched partially.

https://cran.r-project.org/doc/manuals/R-lang.html#Arguments

snaut
  • 2,261
  • 18
  • 37