rrstudioadd-inrstudioapi

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


Here are some of my addins :

enter image description here

For example, I'd like to know programmatically what function is called by "reprex" for the addin "Reprex selection".

If I go to the repo and browse to "reprex/inst/rstudio/addins.dcf" I can see that it is reprex:::reprex_selection().

So I wish to have :

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

Returning the function without naming it would work too.


Solution

  • You can read that addins.dcf file with read.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"
    

    Created on 2021-09-13 by the reprex package (v2.0.0)