Sometimes you just want a project-less RStudio session
If you’ve ever been to an R workshop I gave, you probably heard me say “if the only thing you get out of this workshop is that RStudio projects are awesome and you should use them, this workshop was worth your time”. And I stand by this statement, they are awesome!1
But sometimes you just want a project-less RStudio! When, you ask? Imagine you have an RStudio project open where you’re writing course slides, or a blog post, or a package… And then imagine a student asks a coding question and you want to run their code quickly but don’t want to populate your environment with the objects that code creates. You also don’t want to restart your existing R session, but you want to try out their code in a pristine environment. I find myself in situations like this pretty regularly, and often work through the following steps:
- Go to the issues in the RStudio IDE repository on GitHub
- Search for the character string “new empty session”
- Run the suggested code in the console:
rstudioapi::terminalExecute("open -n /Applications/RStudio.app", show = FALSE)
Hadley Wickham suggests in R for Data Science that “you should consider writing a function whenever you’ve copied and pasted a block of code more than twice”2. So I figured if I keep doing this same set of moves over and over, I should write an addin for that! And a recent Twitter conversation reminded me that I have a personal addins package, addmins3, with one very frequently used addin for Tidyverse style comments with dashes that up to 80 characters.
So I figured now is the time to finally include a second addin to this package addin: launch_rstudio()!
If these two niche addins are useful to you as well, you can install this package using the following:
devtools::install_github("mine-cetinkaya-rundel/addmins")
But more likely you have some sets of actions you do regularly when working in R and your workflow might benefit from having shortcuts for them. Writing your own addins is relatively straightforward, even if you’ve never written an R package before. Pretty much everything you need to know about RStudio Addins can be found here, including instructions for developing your own addins. Additionally, you can find an extensive list of addins people have developed over the years here and searching for #rstats addin on Twitter yields a more current list.