Simplifying RStudio

Sharon Makunura
3 min readApr 20, 2020

One of the challenges of programming is repetition. This applies not only to code, but also to how you maneuver with RStudio. In article, I share some tips on how to minimize this using RStudio’s inbuilt features. This article references RStudio Version 1.2.5033. First, lets define the layout of RStudio.

RStudio is divided into 4 windows. The first is the source. This is where you write your code. Below that is the console. This is where your output is displayed. Unless your output is a plot or graph, then it will be displayed in the bottom right pane. This part of the screen also allows you to view files on your computer, the packages you have installed in RStudio, as well as Help documentation. The top right window allows you to view your data sets and variables, as well as keeps history of all the code you have run.

1. Finding your way within your code.

You can only view less than 30 lines of code in the layout shown above, but when you have ten times as much code to get through, sometimes it is too much scrolling to get to different sections of code. RStudio has a solution. At the bottom of the source screen is an option to quickly move through different sections. By default, it will read (Top Level) as shown in the figure below.

To make use of this, put headings or identifying within your code, surrounded by hashtags:

###################OUTPUTS###################

When you click on the arrow, these type of comments or heading will be listed in order of appearance. Also, if you have functions within your code, these will automatically be added to the listings.

2. Find code you have already used.

The environment tab allows you to scroll through the objects you have created: all the datasets and variables. The History tab is one that is more useful for me. By scrolling the history tab I see the code I have run. The best part is, I can search for particular functions if I have already used them. For example in the screen below I am searching for colnames. The search will output an outline of the uses. Clicking on the tiny blue arrow in the corner will expand the window to show the context within which the code was used. If you double click on the code, it will appear in the console window and you can run it again.

Note that this reviews all the code you have ever run within your profile, not necessarily in that session.

3. Re-run code you have previously run.

Another way to re-run previously used code is through the console window. Apart from being able to scroll through your output, you can scroll through your previously run code using the up and down arrows.

Simply place your cursor at the > arrow at the end, and scroll through.

4. Review Plots

As stated earlier, the plot tab in the bottom right pane will display plots. While viewing plots, it is possible to use the arrow to scroll through the plots without having to rerun the code.

--

--

Sharon Makunura

Data Analyst and Independent Consultant. Writer. Teacher. Mother of Girls.