7  A Quick Tour Around RStudio

As I mentioned in the previous chapter, R comes with a simple built-in graphical user interface, or GUI for short. While you can use this interface to work with R, it is more convenient if you interact with R using a third party software such as RStudio.

Technically speaking, RStudio is an IDE which is the acronym for Integrated Development Environment. This is just the fancy name for any software application that provides comprehensive facilities to programmers for making their lives easier when writing code and developing programs.

Simply put, you can think of RStudio as a “workbench” that gives you an organized working space for interacting with R, while taking care of many of the little tasks that can be a hassle.

7.1 First Contact with RStudio

When you open RStudio, you should be able to see its layout organized into quadrants officially called panes (or panels).

The very first time you launch RStudio you will only see three panes, like in the screenshot below.

Figure 7.1: Screenshot of RStudio when launched for the first time.

As you can tell from the previous screenshot, the left-hand side shows the Console pane which is what we used in previous chapters to write a handful of simple commands, execute them, and inspect the output provided by R.

If RStudio only displays three panes, why do I call them “quadrants”? Where is the fourth pane? Well, to see the extra pane you need to open a file. One way to do this is by clicking on the icon of a blank file with a green plus sign. This button is located in the top-left corner of the icons menu bar of RStudio. A drop-down menu with a long list of available file formats will be displayed, the first option being an “R Script” file (see image below).

Figure 7.2: Opening a new (text) file in RStudio.

Once you open a (text) file, the layout of RStudio will show the Editor quadrant, officially called the Source pane, like in the following screenshot.

Figure 7.3: RStudio layout organized into quadrants.

The visual appearance of RStudio’s quadrants can be a bit intimidating for beginners. But fear not. In the above screenshot, the panes are:

  • Source or editor pane (top left quadrant)

  • Console pane (bottom left quadrant)

  • Environment/History/Connections pane (top right quadrant)

  • Files/Plots/Packages/Help pane (bottom right quadrant)

Pro tip: among many other things, you can change the default location of the panes. If you are interested in knowing what customizing options are available in RStudio, visit the following link:


If you have no previous programming experience, you don’t have to customize anything right now. It’s better if you wait some days until you get a better feeling of the working environment. You will probably be experimenting (trial and error) some time with the customizing options until you find what works for you.

7.2 RStudio Panes in a Nutshell

Sooner or later you will be using all four panes in RStudio. Most programming activities will require working with both the Source and Console panes. Certain operations will involve using the Files tab. Occasionally you will also use one of the tabs in the Environment/History/etc pane. The set of specific tabs that you have to use really depends on the type of work you plan to carry out. You will have time to learn the basics—and not so basics—of every pane throughout the book. The more time you spend in RStudio, and the more you use it, the more features you will discover about it.

7.2.1 Console

Figure 7.4: Console pane

The Console is supposed to be the terminal—or the place—where you type in commands, which R then executes, and where the output of those commands is typically displayed. The truth is that most programmers don’t write commands directly in the console. Instead, what we use is the Source pane to write commands in a text file (e.g. an R-Script file, an R-Markdown file), and then execute the commands from that pane.

The reason for writing commands in a text file and not directly in the console, is because of convenience and organization. Convenience because, as you will see, many commands involve writing several lines of code which can be tricky to write them correctly just by typing in the console. Organization in the sense that having all your commands in a text file makes it easy to store your code, keep track of all the work you do, build upon it, and share it with others.

So, knowing that programmers rarely make direct use of the Console, when do you actually use this pane? I don’t know about the rest of programmers but I can tell you how I personally use it.

One common use of the Console is when I want to calculate basic things like the monthly balance in my credit cards, or the overall score for one of the students in the classes I teach, or some other quick computation. These are types of calculations that I could perfectly perform with any scientific calculator like the one in my smartphone. But more often than not I prefer to do them in R, typically when that’s the tool I have at hand (which happens almost every day).

The other typical situation in which I use the console is when I’m trying out some simple idea or testing if a certain command could work. I like to explore the feasibility of my code with a small example in the console, and then refine it or generalize it by writing code in a text file—using the Source pane.

7.2.2 Files, Plots, Packages, Help

Figure 7.5: Files-Plots-Help pane

The Files quadrant contains multiple tabs.

  • Files: this tab lets you navigate your file system without the need of leaving RStudio. You can move to any directory or folder in your home directory, inspect the contents of a given folder, create a new folder, and perform standard operations on files such as opening, renaming, moving, copying, and deleting a file. In addition, you can also see the working directory, or change to a different directory if you want to.

  • Plots: this tab is used by R Graphics Devices to display any graphic or image produced by an R plotting function.

  • Packages: this tab allows you to install and update R packages. Often, you will want to use functions from external R packages, and to do this you must first install those packages in your system. While it is possible to write commands for doing this, the Packages tab gives you a richer interface to see what packages are already available in your computer, what their versions are, update them if necessary, or uninstall them in case you no longer need them.

  • Help: this is the tab that gives you access to the “help” or manual documentation of functions, objects, tutorials, and demos of a given R package. The preceding chapter contains an example of the manual documentation for the log() function, showing the main anatomy of the so-called R Documentation files.

7.2.3 Source or Editor

Figure 7.6: Source pane

The Source or Editor pane is basically the text editor of RStudio. This is the quadrant you use to edit any text file, again, without the need to leave RStudio. The reason why is called “source” is because the text files edited in this pane are, for the most part, files that contain the commands that R will run. In other words, these files are the source of the commands to be executed.

7.2.4 Environment, History, Connections

Figure 7.7: Environment-History pane

The last quadrant is the pane that contains, at least, the following three tabs: Environment, History, and Connections.

I provide a deeper explanation of the Environment and History tabs in the chapter Session Management. In the meantime, what you need to know about Environment is that this tab is used to list the objects that have being created, or that are available, in a given R session.

In turn, the History tab is a very useful resource that lists all the R commands that you have executed so far. In theory, R will track all the invoked commands since the first time you used it, unless you’ve removed the auxiliary .Rhistory file linked to your working directory, or unless you’ve modified the history mechanism used by your R console.

As for the Connections tab, this plays a more advanced (and somewhat obscure) role that I don’t in this book.

7.3 Exercises

1) In RStudio, one of the panes has tabs Files, Plots, Packages, Help, Viewer.

  1. In the tab Files, what happens when you click the button with a House icon?

  2. Go to the Help tab and search for the documentation of the function mean.

  3. In the tab Help, what happens when you click the button with a House icon?

2) In RStudio, one of the panes has the tabs Environment, History, Connections.

  1. If you click on tab History, what do see?

  2. Find what the buttons of the menu bar in tab History are for.

  3. Likewise, what can you say about the tab Environment?

3) When you start a new R session in Rstudio, a message with similar content to the text below appears on the console (the exact content will depend on your R version):

   R version 3.5.1 (2018-07-02) -- "Feather Spray"
   Copyright (C) 2018 The R Foundation for Statistical Computing
   Platform: x86_64-apple-darwin15.6.0 (64-bit)

   R is free software and comes with ABSOLUTELY NO WARRANTY.
   You are welcome to redistribute it under certain conditions.
   Type 'license()' or 'licence()' for distribution details.

     Natural language support but running in an English locale   

   R is a collaborative project with many contributors.
   Type 'contributors()' for more information and
   'citation()' on how to cite R or R packages in publications.

   Type 'demo()' for some demos, 'help()' for on-line help, or
   'help.start()' for an HTML browser interface to help.
   Type 'q()' to quit R.
  1. What happens when you type (in the console): license()?

  2. What happens when you type (in the console): contributors()?

  3. What happens when you type (in the console): citation()?

  4. What happens when you type (in the console): demo()?