Skip to content

Instantly share code, notes, and snippets.

@dmurdoch
dmurdoch / dupnames.R
Last active February 18, 2024 20:19
Search R package for duplicate definitions
# While in the top level directory of a package, run `dupnames()` to check the source for multiple
# definitions of the same identifier. The *last* definition is the one that will be included in your
# package; earlier ones are overwritten.
containsNames <- function(expr, names) {
if (is.name(expr) && as.character(expr) %in% names)
return(TRUE)
if (is.call(expr)) {
fn <- expr[[1]]
if (is.name(fn) && as.character(fn) == "function")