Simple R Studio Hack That You Should Know

Simple R Studio Hack That You Should Know: RStudio is an open-source tool for programming in R. If you are interested in programming with R, it’s worth knowing about the capabilities of RStudio. It is a flexible tool that helps you create readable analyses and keeps your code, images, comments, and plots together in one place. In this article, we are going to talk about an R studio hack that every R user should know:

Simple R Studio Hack That You Should Know
Simple R Studio Hack That You Should Know

1. Keyboard Shortcuts

If you know RStudio keyboard shortcuts will save lots of time when programming. RStudio provides dozens of useful shortcuts that you can access through the menu at the top: Tools > Keyboard Shortcuts Help. Another way to access RStudio keyboard shortcuts is with a shortcut! To access shortcuts, type Option + Shift + K on a Mac or

Here are some of our favorite RStudio shortcuts:

  • Insert the <- assignment operator with Option + - on a Mac, or Alt + - on Linux and Windows.
  • Insert the pipe operator %>% with Command + Shift + M on a Mac, or Ctrl + Shift + M on Linux and Windows.
  • Run the current line of code with Command + Enter on a Mac or Control + Enter on Linux and Windows.
  • Run all lines of code with Command + A + Enter on a Mac or Control + A + Enter on Linux and Windows.
  • Restart the current R session and start fresh with Command + Shift + F10 on a Mac or Control + Shift + F10 on Linux and Windows.

Another excellent resource for RStudio shortcuts is the official RStudio cheat sheet.

2. Customize the Appearance

RStudio offers a wealth of options to customize the appearance to your liking. Under the RStudio tab, navigate to Preferences > Appearance to explore the many options available. A nice feature of RStudio is that you can quickly click through the Editor theme window to preview each theme.

3. Manage Version Control with GitHub in RStudio

In addition to managing packages in RStudio, you can also use GitHub with RStudio to maintain version control of your projects and R scripts. Check out this article from GitHub and this article from RStudio for all the information you need to integrate Git into your RStudio workflow.

4. Preview and Save Your Plots

Plots generated during an RStudio session are displayed under the Plots tab in the lower-right window. In this window, you can inspect your plots by zooming in and out. If you want to save your plot, you can save the plot as a PDF or image file.

5. Organize Your Work with Projects

RStudio offers a powerful feature to keep you organized; Projects. It is important to stay organized when you work on multiple analyses. Projects from RStudio allow you to keep all of your important work in one place, including code scripts, plots, figures, results, and datasets. Create a new project by navigating to the File tab in RStudio and selecting New Project… You have the option to create your new project in a new directory or an existing directory.

RStudio offers dedicated project types if you are working on an R package or a Shiny Web Application. RStudio Projects are useful when you need to share your work with colleagues. You can send your project file (ending in .Rproj) along with all supporting files, which will make it easier for your colleagues to recreate the working environment and reproduce the results.

6. Manage Package Versions with renv

We love R at Dataquest, but managing package versions can be a challenge! Fortunately, R package management is easier than ever, thanks to the renv (“reproducible environment”) package from RStudio. And now, RStudio includes built-in support for renv. We won’t get into the details of how to use renv with RStudio projects in this blog because RStudio provides you with the info you need in the link we provided and in the vignette. But using renv with RStudio can make R package management much easier, so we wanted to let you know!

The renv the package is replacing the Packrat package that RStudio used to maintain. To use the renv package with your RStudio projects upgrade to the latest version of RStudio and then install the renv package with library("renv"). From there you will have the option to use renv it with all new projects.

7. Easy Links to Documentation

Under the Help tab in the lower-right window, you’ll find handy links to the online documentation for R functions and R packages. For example, if we search for information about the install.packages() function using the search bar, the official documentation is returned:

We can also access documentation in the Help tab by prepending a package or function with ?, (e.g. ?install.packages) and running the command into the Console. With either approach, RStudio auto-fills matching function names as you type.

Comments are closed.