我想通过将函数名称存储在列表中来从卸载的包中调用函数。
通常我只会使用:
library(shiny)
pagelist <- list("type" = "p") # object with the function name (will be loaded from .txt file)
get(pagelist$type[1])("Display this text")
但因为在编写包时不允许加载库,所以我必须使用类似的东西
get(shiny::pagelist$type[1])("Display this text")
这是行不通的。有没有办法从列表中存储的函数名称调用函数,而无需加载库?请注意,应该可以调用许多像这样的不同函数(全部来自同一个包),因此只需使用例如
if (pagelist$type[1] == "p"){
shiny::p("Display this text")
}
需要很长的 if else 语句列表。
Use getExportedValue
:
getExportedValue("shiny",pagelist$type[1])("Display this text")
#<p>Display this text</p>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)