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.
This package holds a couple addins I've made that have nothing to do with any specific package.
rstudioapi_addin
This is sort of meta. This addin calls functions from the rstudioapi package that you might use in your own addin. You can select text (or not) and activate the source editor (or the Console), then call this addin to expose all the information available returned by these functions:
getActiveProject()
getActiveDocumentContext()
getSourceEditorContext()
getConsoleEditorContext()
primary_selection(getSourceEditorContext()
Results are both print()
ed and str()
ed. It's not beautiful, but it gets the job done. You are in a better to position to program with these functions after you see the gory details with your own eyes.
To use this addin:
rstudioapi
package (see above)devtools::install_github("jennybc/jadd")
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:
rstudioapi
package (see above)devtools::install_github("jennybc/jadd")
Take with a grain of salt, because I have two four eight entire hours of experience at this point.
rstudioapi
addin -- so I can select arbitrary text or put the cursor in an editor windows or the Console AND see what the rstudioapi functions return..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"?