Как вызвать standardGeneric с именем переменной функции
Следующий код выдает предупреждение:
test_slot = "testslot"
setGeneric(name = test_slot,
def = function(object){
standardGeneric(test_slot)
},
where = globalenv()
)
[1] "testslot"
Warning message:
In .recursiveCallTest(body, fname) :
the body of the generic function for ‘testslot’ calls 'standardGeneric' to dispatch on a different name ("test_slot")!
Я ожидал бы, что это будет эквивалентно:
setGeneric(name = "testslot",
def = function(object){
standardGeneric("testslot")
},
where = globalenv()
)
Что случилось?
1 ответ
Это не ответит, почему оригинальный блок кода вышел из строя, но обходной путь должен был бы сделать:
test_slot = "testslot"
setGeneric(name = test_slot,
def = eval(parse(text = paste0("function(object){",
"standardGeneric('", test_slot, "')",
"}")))
},
where = globalenv()
)
то есть построить всю def
аргумент, чтобы быть оцененной функцией.