RStudio IDE is the best development environment for the R programming language so far. Not many alternatives seem to beat the RStudio IDE especially if your work heavily relies on R and its modern ecosystem (yet has still not been convinced hundred percent but I am close enough). There are some alternatives:

  • Nvim-R is a Vim plugin (actual support goes to neovim) actually a game changer in the town.

  • ESS has just been great and unavoidable for over the years; however, for those who just want a decent editor, and not desire, or able to, fully adapt themselves to the Emacs world will probably not get a fruitful experience.

  • Visual Studio Code This is not a command line alternative, but may be worth to look if you desire some difference. @milesmcbain explained this further in this post here.

Therefore one should always reconsider its alternatives to which suits best for its needs. ESS/Nvim-R can really be handy when require to connect to a remote server e.g. via SSH and RStudio is the best on desktop and need to do some procedural data analysis.

This post is mainly about RStudio Desktop IDE. I compile a list of some keyboard shortcuts, packages, snippets and add-ins boosting my productivity that are usually present my in use everyday tasks.

Chapters

Packages

The packages mentioned here just indicates how they can improve the working, not get your actual work written. The more packages can be found in R-infrastructure group.

microbenchmark

You can measure the performance of computing with microbenchmark which computes each argument 100 times to give results on average. Further, the benchmark can be visualized by autoplot() function, which is dependent upon the ggplot2 package. The alternative of this package in base R can be the system.time() function.

install.packages("microbenchmark")

profvis

Profvis is a nice tool to perform profiling, understand the bottlenecks and how the R spends its time. A must in the toolbox.

install.packages("profvis")

lintr

Lintr package gives you nice ‘linting’ which are gently reminders to have command over your own styling and syntax, as well as some nice warnings especially when a variable is declared but not later used.

Lintr will boost up the quality of the R code as the software should always be written for the humans. Therefore, run lintr::lint("file.R") and/or lintr::lint_package().

install.packages("lintr")

fledge

This R package assists you to bump versions by the terms of major, minor and patch (according to the Semantic Versioning https://semver.org/) and save the git commit descriptions (only lines starting with * asterisks or - dash are considered) in a file called NEWS.md1 (according to the Keep a Changelog https://keepachangelog.com).

When you write a package, document everything you can because of the Eagleson’s Law.

“Any code of your own that you haven’t looked at for six or more months might as well have been written by someone else.”

remotes::install_github("krlmlr/fledge")

[1] Although it says Don’t let your friends dump git logs into changelogs.

wordcountaddin

This package counts the characters in an RMarkdown document. Also gives more information about the readability statistics, which sometimes gives interesting results in some cases. See the GitHub repo here.

devtools::install_github("benmarwick/wordcountaddin")

Add-ins

RStudio add-ins is just its extension mechanism to customize your working environment. Your productivity can significantly be increased together with lots of useful add-ins which you previously doing by hand spending hard time to fix the things to look it correct. I recently discovered the add-ins and they just great.

Most of the add-ins requires the devtools package.

install.packages("devtools")

I here curate some of the addins I like. You can click here if you prefer to see a more comprehensive list of addins.

datapasta

I have really found datapasta a huge time saver. You can see the GIF above which I recorded in my working environment. It formats, add quotes, and concatenate the lists and vectors. My favorite things it does: 1) Paste (as data.frame and vector) 2) Fiddle Selection 3) Toggle Vector Quotes. It’s dependent upon ‘readr’, ‘clipr’ packages, and uses RStudio’s API (possible to use without it). It’s on CRAN, so installation is easy as install.packages("datapasta").

However, I did not find useful yet to assign any keyboard shortcut to any of the provided functions.

ggThemeAssist

A Shiny based GUI theme assistant for ggplot2 can significantly help your plotting work.

devtools::install_github("calligross/ggthemeassist")

remedy

A RMarkdown addin which is useful e.g. when especially constructing tables.

devtools::install_github("ThinkR-open/remedy")

caseconverter

This addin has actually been developed by me. It basically change the case of the selected text either in the editor or in the R console.

devtools::install_github("strboul/caseconverter")

Keyboard-shortcuts

I will list the shortcuts that I usually exercise. For a comprehensive list, you can always visit Tools > Keyboard Shortcuts Help.

The updated link: https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts

General

Command Windows/Linux Mac My comments
Keyboard shortcut reference Alt + Shift + K Option + Shift + K a shortcut to rule them all
New R file Ctrl + Shift + N Cmd + Shift + N  
Function help F1 F1  
Function source code F2 F2  
Search the history from console Ctrl + ↑ Cmd + ↑ powered by .Rhistory
Move cursor to editor Ctrl + 1 Ctrl + 1 moving without touching mouse
Move cursor to console Ctrl + 2 Ctrl + 2 (not touching mouse!)
Clear console Ctrl + L Cmd + L  
Open tab search Ctrl + Shift + . Ctrl + Shift + .  
Previous tab Ctrl + F11 Ctrl + F11  
Next tab Ctrl + F12 Ctrl + F12  
First tab Ctrl + Shift + F11 Ctrl + Shift + F11  
Last tab Ctrl + Shift + F12 Ctrl + Shift + F12  
Delete line Ctrl + D Cmd + D  
Autocompletion Tab Tab also Ctrl + Space
Assignment operator Alt + - Option + - ’<-‘
Pipe operator Ctrl + Shift + M Cmd + Shift + M ’%>%’ from magrittr
Add header Ctrl + Shift + R Cmd + Shift + R # Header - - - (…)
Goto function/file Ctrl + . Cmd + . works in a .Rproj
Find in files Ctrl + Shift + F Cmd + Shift + F search in all files within scope
Comment/Un-comment line Ctrl + Shift + C Cmd + Shift + C when lines selected
Re-indent lines Ctrl + I Cmd + I  
Re-indent comments Ctrl + Shift + / Cmd + Shift + / indents roxygen docs
Reformat code Ctrl + Shift + A Cmd + Shift + A good but usually odd
Focus to plot Ctrl + Shift + 6 Ctrl + Shift + 6 return to the main view with 0
Restart R session Ctrl + Shift + F10 Cmd + Shift + F10 ‘Session > Restart R’
       

RMarkdown (.Rmd files)

Command Windows/Linux Mac Note
Add a new chunk Ctrl + Alt + I Cmd + Option + I adds R chunk by default
Run all previous chunks Ctrl + Alt + P Cmd + Option + P  
       

Package Development

Command Windows/Linux Mac Note
Build and Reload Ctrl+Shift+B Cmd+Shift+B devtools::install()
Load All (devtools) Ctrl+Shift+L Cmd+Shift+L devtools::load_all()
Test Package (Desktop) Ctrl+Shift+T Cmd+Shift+T devtools::test()
Test Package (Web) Ctrl+Alt+F7 Cmd+Alt+F7  
Check Package Ctrl+Shift+E Cmd+Shift+E devtools::check()
       

Seeing the customized keyboard shortcuts from the add-ins which are stored in. If you are in any .nix based systems:

cd ~/.R/rstudio/keybindings
cat addins.json

If you modified any other shortcuts, also check editor_bindings.json and rstudio_bindings.json files.

Code Snippets

They are great especially when I am in a long debugging process, needed to type the similar things to the console to invoke the commands every time that usually an environment cleaning and restarting session is required. This article explains the basics and I shared my snippets here.


NOTE: I will keep this post updated as long as new shortcuts, tools and add-ins come along.