About RStudio
As with other programming languages, there is a huge variety of IDEs available for R. IDEs are applications that make code development easier and clearer for the programmer. RStudio is one of the most important ones for R, and it is especially recommended to write web applications in R with Shiny because this contains features specially designed for this purpose. Additionally, RStudio provides facilities to write C++, Latex, or HTML documents and also integrates them to the R code.
RStudio also provides version control, project management, and debugging features among many others.
Installing RStudio
RStudio for desktop computers can be downloaded from its official website at http://www.rstudio.com/products/rstudio/download/ where you can get versions of the software for Windows, MAC OS X, Ubuntu, Debian, and Fedora.
A quick guide to RStudio
Before installing and running RStudio, it is important to have R installed. As it is an IDE and not the programming language, it will not work at all. The following screenshot shows RStudio's starting view:
At the first glance, the following four main windows are available:
- Text editor: This provides facilities to write R scripts such as highlighting and a code completer (when hitting Tab, you can see the available options to complete the code written). It is also possible to include R code in an HTML, Latex, or C++ piece of code.
- Environment and history: They are defined as follows:
- In the Environment section, you can see the active objects in each environment. By clicking on Global Environment (which is the environment shown by default), you can change the environment and see the active objects. You can find more information about environments in a chapter dedicated to this topic in the book Advanced R, by Hadley Wickham. It is available at http://adv-r.had.co.nz/Environments.html.
- In the History tab, the pieces of codes executed are stored line by line. You can select one or more lines and send them either to the editor or to the console. In addition, you can look up for a certain specific piece of code by typing it in the textbox in the top right part of this window.
- Console: This is an exact equivalent of R console, as described in Quick guide of R.
- Tabs: The different tabs are defined as follows:
- Files: This consists of a file browser with several additional features (renaming, deleting, and copying). Clicking on a file will open it in editor or the Environment tab depending on the type of the file. If it is a
.rda
or.RData
file, it will open in both. If it is a text file, it will open in one of them. - Plots: Whenever a plot is executed, it will be displayed in that tab.
- Packages: This shows a list of available and active packages. When the package is active, it will appear as clicked. Packages can also be installed interactively by clicking on Install Packages.
- Help: This is a window to seek and read active packages' documentation.
- Viewer: This enables us to see the HTML-generated content within RStudio.
- Files: This consists of a file browser with several additional features (renaming, deleting, and copying). Clicking on a file will open it in editor or the Environment tab depending on the type of the file. If it is a
Along with numerous features, RStudio also provides keyboard shortcuts. A few of them are listed as follows:
Description |
Windows/Linux |
OSX |
---|---|---|
Complete the code. |
Tab |
Tab |
Run the selected piece of code. If no piece of code is selected, the active line is run. |
Ctrl + Enter |
⌘ + Enter |
Comment the selected block of code. |
Ctrl + Shift + C |
⌘ + / |
Create a section of code, which can be expanded or compressed by clicking on the arrow to the left. Additionally, it can be accessed by clicking on it in the bottom left menu. |
|
|
Find and replace. |
Ctrl + F |
⌘ + F |
The following screenshots show how a block of code can be collapsed by clicking on the arrow and how it can be accessed quickly by clicking on its name in the bottom-left part of the window:
Clicking on the circled arrow will collapse the Section 1
block, as follows:
The full list of shortcuts can be found at https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts.
Note
For further information about other RStudio features, the full documentation is available at https://support.rstudio.com/hc/en-us/categories/200035113-Documentation.