Here is an example:
setGeneric("loadBim",
function(pl_info, ...) {
standardGeneric("loadBim")
})
setMethod("loadBim",
signature(pl_info = "PlInfo"),
function(pl_info) {
loadFFDF(pl_info@ff_dir_trio["bim"])
})
setGeneric("loadFam",
function(pl_info, ...) {
standardGeneric("loadFam")
})
setMethod("loadFam",
signature(pl_info = "PlInfo"),
function(pl_info) {
loadFFDF(pl_info@ff_dir_trio["fam"])
})
setGeneric("loadFrq",
function(pl_info, ...) {
standardGeneric("loadFrq")
})
setMethod("loadFrq",
signature(pl_info = "PlInfo"),
function(pl_info) {
loadFFDF(pl_info@ff_dir_trio["frq"])
})
All these S4 methods are similar, they differ only for some file extension names: bim, fam, and frq. I am wondering is there some metaproramming technique available for simplifying them (generating them programmatically)?
I found out one solution:
loadPlinkMeta = gtools::defmacro(ext, method_name, expr = {
setGeneric(method_name,
function(pl_info, ...) {
standardGeneric(method_name)
})
setMethod(method_name,
signature(pl_info = "PlInfo"),
function(pl_info) {
loadFFDF(pl_info@ff_dir_trio[ext])
})
})
loadPlinkMeta("bim", "loadBim")
loadPlinkMeta("fam", "loadFam")
loadPlinkMeta("frq", "loadFrq")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.