Skip to content

rmflight/jadd

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RStudio addins

RStudio addins let you execute a bit of R code or a Shiny app through the RStudio IDE, either via the Addins dropdown menu or with a keyboard shortcut. Coupled with functions from the rstudioapi package, this means you can operate on your own R code, which is awesome.

RStudio docs on addins (with examples): https://rstudio.github.io/rstudioaddins/

To use addins:

  • Run RStudio v0.99.878 or later
  • Run rstudioapi package v0.5 or later
    • install.packages("rstudioapi", type = "source")
  • Populate your Addins dropdown menus with some examples
    • devtools::install_github("rstudio/addinexamples", type = "source")

These recent addins / Shiny gadgets inspired me to try my hand at this:

assign_defaults_addin

The assign_defaults_addin helps you develop and debug a function. Scenario: you're working on a function and need to walk through the body as if it were top-level code. But it is a PITA to set all the arguments to their default values. So you just fiddle with the function at arms length, convinced you can spot the problem and fix it this way. Sure you can.

Define your function. Select its name and Addins > Assign default values will make assignments to the global environment. Arguments that have a default will be set to that value. Arguments with no default are ignored -- you must set those to something sensible yourself. And ... must be dropped, so have fun with that too! Fix your function. When you're feeling lucky, restart R to clean out global environment and load/test the function properly.

To use this addin:

  • Run very recent RStudio IDE and rstudioapi package (see above)
  • devtools::install_github("jennybc/jadd")
  • look for it in the Addins menu

An animation of the above

Observations on the development process

Take with a grain of salt, because I have two four entire hours of experience at this point.

  • Every addin deserves a demo gif.
  • The addin function shall not be a monster function. Make it as small as possible and put the smarts in other functions.
  • Why? So the discrete pieces of smarts are easier to develop and test. Maybe even reuse in other addins?
  • Addins live inside an R package, so take advantage of that, e.g. write tests and some documentation.
  • Question: Is the model "one package per addin" or "one addin package per person" or ???
  • Question: If your addin operates on a text selection, it feels impossible to develop this function in the usual way. As in, you can't do devtools::load_all() then simultaneously have some relevant text selected AND execute the main addin function on it. I had to do "Build & Reload" and run the actual addin from the menu. Am I missing something? This was another reason to shift functionality out of the addin function.
  • Question: My Addins menu seems to show all the addins that are ?within packages on my .libPaths()?. I bet people will start to put addins in their normal packages, i.e. packages don't exist solely for the purpose of making an addin. Are those really all going to show up in my Addins menu all the time? Will there be a way to say "this addin only makes sense when package <x> is explicitly loaded"?

About

RStudio addins

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 100.0%