Skip to content

Instantly share code, notes, and snippets.

@briandk
Created February 23, 2012 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandk/1893800 to your computer and use it in GitHub Desktop.
Save briandk/1893800 to your computer and use it in GitHub Desktop.
Fun with parameter matching in R
foo <- function(..., values) {
return(values)
}
bar <- function(values, ...) {
return(values)
}
# foo() will fail to match on "values" and claim there's no default
foo(value = "red")
bar(value = "red")
# If we give the functions a default, we'll see that bar() respects our input
# but foo() doesn't
foo <- function(..., values = "green") {
return(values)
}
bar <- function(values = "green", ...) {
return(values)
}
foo(value = "red")
bar(value = "red")
# But specifying the argument name in full seems to match
foo(values = "red")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment