Closed Captioning Closed captioning available on our YouTube channel

R tip: Addins and keyboard shortcuts

Discover an easy way to use key-value pairs in R

Hi. I’m Sharon Machlis at IDG Communications, here with Do More With R: RStudio Addins, and keyboard shortcuts.
If you’ve never used RStudio addins, they’re definitely worth a look. I’ll show you one of my favorites: bare combine.
I’ve got text with the names of . . . something. I’d like to turn it into an R vector. Adding quotation marks around each one gets kind of annoying if there are more than a couple of items. But the bare combine addin solves the problem.
You install addins the same way you install packages: with install.packages if they’re on CRAN, or whatever you use to install from GitHub if they’re on GitHub. Bare combine is part of Bob Rudis’s hrbraddins on GitHub, so you can install it with this code: remotes::install_github("hrbrmstr/hrbraddins")
Instead of installing a package with functions, this installs a package with several RStudio addins. You’ll find those in RStudio’s Addins menu above the upper-left scripts pane
As you can see, I have a lot of addins installed!
I’ll go to the text file and copy a comma-separated list of browser names. As you can see, they don’t have quotes around them.
Back in RStudio I’ll paste that text, highlight it, then click on the add-in
And voila, code for a properly formatted R vector. It even works if the items aren’t comma-separated.
I’ll highlight this text and run the bare combine addin again
I’m guessing you may be thinking that it’s kind of cumbersome, if you have a lot of addins and need to scroll through a long list of them. At that point, your addin might not save much time. The good news is, you can create a keyboard shortcut for any addin.
Go to Tools > Modify Keyboard Shortcuts in RStudio.
You’ll first see all the built-in possibilities. If you keep scrolling, you’ll eventually see your addins. Or, much easier, you can use the search box to look for your addin.
Click into the empty field under the Shortcut column, and type your key combination. I’ll choose control-alt-c and then click Apply.
Now if I select the text and hit control-alt-c, my addin works -- without having to scroll through the whole addin menu.
How cool is that?
Dean Attali keeps a whole list of addins on GitHub, you can see it at
Take a look at the list, there might be a couple of addins you didn’t know about that will help you speed up your R workflow. Some conventional R packages also include addins, such as datapasta and bookdown.
That’s it for this episode, thanks for watching! For more R tips, head to the Do More With R page at https go dot infoworld dot com slash more with R, all lowercase except for the R. You can also find the Do More With R playlist on YouTube. Hope to see you next episode!