Skip to content

Instantly share code, notes, and snippets.

@multidis
Created December 26, 2013 21:15
Show Gist options
  • Save multidis/8138757 to your computer and use it in GitHub Desktop.
Save multidis/8138757 to your computer and use it in GitHub Desktop.
Match formula, data call in R function and create corresponding dataframe. Typical beginning of new functions utilizing formula interface.
someFun <- function(formula, data, ...) {
mc <- match.call()
m <- match(c("formula","data"), names(mc), 0L)
mf <- mc[c(1L, m)]
mf[[1L]] <- as.name("model.frame")
mf <- eval(mf, parent.frame())
data.st <- data.frame(mf)
return(data.st)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment