I am struggling with a problem that is recognized, but for which I still have to find an easy solution: how to catch the vague arguments passed into R-functions when the function definition includes an ellipsis or three points ....
As stated in Wickham Advanced R:
Use ...occurs at a price - any arguments with errors will not raise an error, and any arguments after ...should be fully named. This makes it easy to make typos invisible.
Here is an example:
myfun <- function(x, ...)
UseMethod("myfun")
myfun.character <- function(x, toLower = FALSE, ...)
cat("Sent and transformed by myfun:", ifelse(toLower, tolower(x), x), "\n")
myfun("Test String with CaPiTaLs.")
## Sent and transformed by myfun: Test String with CaPiTaLs.
myfun("Test String with CaPiTaLs.", toLower = TRUE)
## Sent and transformed by myfun: test string with capitals.
myfun("Test String with CaPiTaLs.", tolower = TRUE)
## Sent and transformed by myfun: Test String with CaPiTaLs.
myfun("Test String with CaPiTaLs.", toLower = TRUE, notDefined = 1)
## Sent and transformed by myfun: test string with capitals.
toLower , , , . , , , , , - ....
, ... list(...), , , , , , ....
, , - , ...? , Julia, !
:
, -, , - . , :
myfun2 <- function(x, ...)
UseMethod("my fun")
myfun2.character <- function(x, toLower = FALSE, ...)
cat("Sent and transformed by myfun:", ifelse(toLower, tolower(x), x), "\n", ...)
myfun2("Test String with CaPiTaLs.", tolower = TRUE)
## Sent and transformed by myfun: Test String with CaPiTaLs.
## TRUE
myfun2("Test String with CaPiTaLs.", toLower = TRUE, notDefined = 1)
## Sent and transformed by myfun: test string with capitals.
## 1
myfun2("Test String with CaPiTaLs.", sep = "\tXX\t")
## Sent and transformed by myfun: XX Test String with CaPiTaLs. XX