Skip to content

Instantly share code, notes, and snippets.

@cbare
Created September 14, 2012 17:49
Show Gist options
  • Save cbare/3723488 to your computer and use it in GitHub Desktop.
Save cbare/3723488 to your computer and use it in GitHub Desktop.
Handling of missing arguments in R
# How the "missingness" status of arguments can be passed down
# the call stack. (Thanks Martin Morgan!)
bar <- function(q,...) {
cat(q)
foo(...)
}
foo <- function(a=123) {
if (missing(a))
"I'm missing something"
else
"a ok"
}
@cbare
Copy link
Author

cbare commented Sep 14, 2012

bar(q=123)
123[1] "I'm missing something"
bar(q=123, a=456)
123[1] "a ok"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment