Created
February 23, 2012 17:10
-
-
Save briandk/1893800 to your computer and use it in GitHub Desktop.
Fun with parameter matching in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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