Skip to content

Instantly share code, notes, and snippets.

@HughParsonage
Last active July 14, 2017 09:39
Show Gist options
  • Save HughParsonage/18e3005ef533acf93261e1f73296a995 to your computer and use it in GitHub Desktop.
Save HughParsonage/18e3005ef533acf93261e1f73296a995 to your computer and use it in GitHub Desktop.
formalCoverage <- function(fn) {
formalz <<- formals(fn)
bod <<- as.character(body(fn))
formal_present <- function(formal) {
formal_dots_escaped <<- gsub(".", "\\.", formal, fixed = TRUE)
any(grepl(pattern = paste0("(?:\\b|\\s)", formal_dots_escaped, "(?:\\b|\\s)"),
x = bod,
perl = TRUE))
}
formals_present <<- vapply(names(formalz), formal_present, FALSE)
if (!all(formals_present)) {
names(formals_present)[!formals_present]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment