Most people who use R, use some kind of interface other than the one that is provided out of the box if you download R. (If you don’t know what R is yet, first read Chapter 15.)
At the moment, the most popular interface by far is RStudio, which is often called an Integrated Development Environment (IDE) for R. That sounds really cool and fancy, but basically, it just means that it has lots of functionality to make your life easier if you work with R.
RStudio is Free/Libre Open Source Software (FLOSS), and you can download it for free from https://www.rstudio.com/products/rstudio/download/. Once it is installed, you can start it, in which case you should see something similar to what is shown in Figure 16.1.3
R itself lives in the bottom-left pane, the console. Here, you can interact directly with R. You can open R scripts in the top-left pane: these are text files with the commands you want R to execute. The top-right pane contains the Environment tab, which shows all loaded datasets and variables; the History tab, which shows the commands you used; the Connections and Build tabs, which you will not need unless you’re a pretty advanced user; and optionally, the Git tab, if you’re working with a project that is a Git repository (see Chapter 11). The bottom-right pane contains a Files tab, showing files on your computer; a Plots tab, which shows plots you created; a Packages tab, which shows the packages you have installed; a Help tab, which shows help ages about specific functions; and a Viewer tab, which can show HTML content that was generated in R.
It’s already easy to see how RStudio make working with R more userfriendly and efficient. For example, RStudio’s panes facilitate opening multiple R scripts or R Markdown files simultaneously; they allow you to cycle through the history of all the plots you created; they conveniently allow you to read help pages right next to your R script and R itself, living in the console; and they allow you to inspect all R objects you loaded into your workspace. But, there’s more. In this Chapter, some of this additional functionality will be discussed.
RStudio projects allow you to bundle related files into one package - well, one project. If you work with R through RStudio, you compartmentalize your projects into RStudio projects. Each project can have its own settings, and, importantly, has a root directory that allows you to refer to files using relative paths from that root directory using the
here R package. That allows R Projects to move across PCs without breaking (before the awesome Jenny Bryan wrote the
here package, files and directory were hardcoded in R scripts, which made those scripts much less portable of course).
RStudio allows you to create a new RStudio project by cloning a Git repository (if you don’t know what that is, see Chapter 11). And if RStudio detects that an RStudio project is a Git repository, it will add a Git tab to the top-right pane, which allows you to do some basic interactions with Git right from RStudio. Also, RStudio has a Terminal tab in the bottom-right pane, which allows you to interact with Git directly using the command line.
Another important reason to use RStudio is to be able to use cool dark themes. You can change your theme through the options dialog: open the Tools menu, select the Global Options, and in section Appearance, you can select your theme. The theme I use is a customized version of the Panda theme, and you can download it from https://gitlab.com/snippets/1846452. Unlike most themes, this theme does not make the comments kind of fade into the background, but instead, comments are bright yellow. Since comments are usually really important (unless you’re a really experienced coder perhaps, but then you probably won’t be reading this), that works better for me. But you can download many more themes of course.
It is easy to change RStudio’s appearance; simply open the options dialog by opening the Tools menu and then selecting the Global Options; in section Appearance, the theme can be selected.↩︎