[SOLVED] How to test whether an R function is defined to accept its input as `…`


What would be a proper way to programmatically test whether a given R function accepts its main input as dot-dot-dot or via named argument?

For example, consider the difference between max() and log(). Whereas max() is defined to take ..., log() expects a numeric vector x.

How can I test a function for that difference?

For example:

# ddd stands for dot-dot-dot
is_main_input_ddd(max) # true
is_main_input_ddd(log) # false


From the comments of @rawr and @camille:

is_main_input_ddd <- function(.f) {
  names(formals(args(.f)))[1] == "..."

#> [1] TRUE
#> [1] FALSE

Created on 2022-01-28 by the reprex package (v2.0.1.9000)

Answered By – Emman

Answer Checked By – Terry (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *