Last active
November 11, 2020 01:28
-
-
Save s-u/6c7f88d209747294653d5e11c5c45dbe to your computer and use it in GitHub Desktop.
Generate S3Method() exports
This file contains hidden or 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
## automatic generation of S3Method() exports for a NAMESPACE | |
all = ls(2) | |
## find generics | |
isg = sapply(all, function(o) length(grep("UseMethod", deparse(get(o))))) | |
gens = names(isg[isg > 0]) | |
## check some most common primitives | |
for (gen in c("+","-","$","$<-")) | |
if (any(substr(all, 1, nchar(gen) + 1) == paste0(gen, "."))) | |
gens = c(gens, gen) | |
## find all methods for the generics | |
ex = unique(unlist(lapply(gens, function(g) { | |
o <- all[substr(all, 1, nchar(g) + 1) == paste0(g, '.')] | |
c(paste0("S3method('", g, "','", gsub("^.*\\.", "", o), "')" ), | |
paste0("export('", o, "')")) | |
}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment