10.1 Advanced features of RStudio

Back in the introductory session, we learned that RStudio is a front-end for R. More specifically, RStudio is an integrated development environment that makes it more straightforward to do a lot more than just interact with the console. Much of these features are specifically designed with programming in mind and so we will give a short introduction to them.

10.1.1 Projects, projects, projects

One of the most useful features of RStudio is it’s ability to separate your work into different projects. Throughout the tutorials, you might have amassed a large number of files (i.e. datasets, scripts and so on) with little obvious organisation. You might have also had to set your working directory repeatedly.

This can become very tedious when you are working on multiple things at once in R. Instead, you can very easily subdivide your work into different RStudio projects, which are essentially separate working directories. You can make brand new ones or associate them with existing work.

You can see here for a more detailed explanation on how to manage projects in RStudio.

10.1.2 Everyone has a history

Another useful feature of RStudio (and also the standard R distribution) is the fact that every command, function and input you type to the console is stored as a history. You can access this very easily using the function history. For example:

# show recent command history
history()

In RStudio, this command will actually open the history pane and show you previous commands that you have run. You can even use the buttons at the top of this pane to reread commands into the console (i.e. To Console) or copy them into an R script (To Source).

There is also an even easier way for you to quickly access the history or previously run commands when you are in the console. You can simply press the up key on your keyboard to rerun the previous lines. This can save you a lot of time and retyping.

10.1.3 Tab complete and other hotkeys

When typing code into a script or the R console, RStudio allows you to do something called tab completion. This simply means if you hit the tab key while typing a function or object name, it will give you a list of options. For example, try typing pl into the R console and then pressing tab. You will see a list of available functions and you can then select the function you want from them.

Tab completion also works within a function too. Try using tab complete to call the function plot and then pressing it again inside the brackets. You will see the arguments the function requires and if you hover over them, a small pop-up will give you a brief explanation of what they are.

There are actually a large number of keyboard based shortcuts you can make use of with Rstudio - these include useful things like Ctrl + 1 or Ctrl + 2 to switch between the console and script panes. You can see a whole list of them here or by selecting Tools > Keyboard Shortcuts Help from the menu bar at the top of the program.