在 RStudio 中给定包和插件名称,获取调用的函数

in RStudio given a package and addin name, get the function that is called

这是我的一些插件:

例如,我想知道以编程方式“reprex”为插件“Reprex selection”调用了什么函数。

如果我转到存储库并浏览到“reprex/inst/rstudio/addins.dcf”,我可以看到它是 reprex:::reprex_selection().

所以我希望有:

magic("reprex", "Reprex selection")
# [1] "reprex_selection"

返回函数而不命名它也可以。

您可以使用 read.dcf():

阅读 addins.dcf 文件
magic <- function(package, name) {
  addins <- read.dcf(system.file("rstudio/addins.dcf", package = package))
  with(as.data.frame(addins), Binding[Name == name])
}
magic("reprex", "Reprex selection")
#> [1] "reprex_selection"

reprex package (v2.0.0)

创建于 2021-09-13