What is RStudio?
R is an open-source software environment for statistical computing and graphics that runs on Windows, Mac OS, and many UNIX platforms. Unlike many other programs, users interact with R through a command line rather than through a graphical user interface. While such an interface may be unfamiliar to many users, its primary strength is the ability for users to develop scripts of commands to perform various analyses that can then be easily repeated.
RStudio is an open-source integrated development environment (IDE) that serves as a front-end “on top” of R. RStudio eases the user’s interaction with R by providing some of the conveniences of a GUI and, more importantly, a means for efficiently constructing and running R scripts. Among other conveniences, RStudio provides a four-panel layout that includes a feature-rich source-code editor (includes syntax highlighting, parentheses completion, spell-checking, etc.), a tight link to the R console, a system for examining objects saved in R, an interface to R help, and extended features to examine and save plots.
Go to the RStudio desktop download page.
Select the link from the “Installers for Supported Platforms” list that corresponds to the operating system appropriate for your computer. Either run the program or note where this executable program is saved on your computer.
If you did not run the program, then locate and run the downloaded file (called “RStudio-0.99.484.exe” or similar if the version number has changed … the version is now at least 1.1.383).
Nexton the first “Welcome” dialog box (depending on your version of Windows you may receive security warnings before this dialog box appears).
Select a location to install RStudio (simply use the default location if the location is not important to you – in the dialog box below I installed in a custom directory). Press
Decide whether or not to create a shortcut in the Start Menu folder (I suggest you DO). Press
RStudio should then begin installing files into the directory you chose previously. If everything goes well then you should get one last dialog box noting such. Press
If you did not create a shortcut above then you will need to locate the “rstudio.exe” file inside the “RStudio/bin” folders inside the folder you chose to install RStudio in. On my computer, for example, this file is inside of “C:/apps/RStudio/bin”.
Global Optionssubmenu. In the ensuing dialog box select the
Generalicon on the left (this should already be selected).
Depending on your installation, the R version should read “[Default][32-bit]” followed by the path to the R program (as shown in the dialog box below). If you installed the 64-bit version of R, then select the
Change...button and then “use your machine’s default version of R64 (64-bit)”.
You can either leave the other selections at their defaults or change them as you see fit (my preferences are shown in the dialog box below). However, I strongly urge you to deselect “Restore .RData into workspace at startup” and make sure “Save workspace to .RData on exit:” is set to “Never.”
Packagesicon in the Global Options dialog box opened above. It is useful to set a CRAN mirror in this dialog box. I prefer the “Global (CDN) - Rstudio” option but you may want to choose a location nearer to you (through the
Change...button). All other options can remain at their defaults.
Codeicon in the Global Options dialog box opened above and the
Displaytab. I suggest, in addition to the default selections, selecting the “Highlight selected line,” “Show margin,” and “Show syntax highlighting in console input.”
At times I find the code completion options in RStudio irritating. If you do as well, you can either turn this option off or tweak its settings within the
Completiontab under the
Codeicon in the Global Options` dialog box opened above.
No other options need to be set for most introductory purposes. Press
RStudio is organized around a four-panel layout.
The upper-left panel is the R Script Editor. R commands are typed into this panel and submitted to the R Console in the lower-left panel. For most applications, you will type R commands into the Script Editor and submit them to the Console; you will not type commands directly into the Console. The Script Editor is a high-level text editor, whereas the Console is the R program.
The upper-right panel contains at least two tabs — Environment and History. Many items listed under the Environment tab can be double-clicked to open them for viewing as a tab in the Script Editor. The History tab simply shows all of the commands that you have submitted to the Console during the current session.
The lower-right panel contains at least five tabs – Files, Plots, Packages, Help, and Viewer. The Plots tab will show the plots produced by commands submitted to the Console. One can cycle through the history of constructed plots with the arrows on the left side of the plot toolbar and plots can be saved to external files using the “Export” tab on the plot toolbar (see figure above). A list of all installed packages is seen by selecting the Packages tab (packages can also be installed through this tab as described in a separate document). Help for each package can be obtained by clicking on the name of the package. The help will then appear in the Help tab.
Your primary interaction with RStudio will be through developing R scripts in the Script Editor, submitting those scripts to the Console, and viewing textual or tabular results in the Console and graphical results in the Plot panel. In this section, I briefly introduce how to construct and run R scripts in RStudio.
One opens a blank file for an R script by selecting the
New icon () and then
R Script; selecting the
New submenu, and
R Script item; or with
<CTRL>+<Shift>+N. In the newly created Script Editor panel, type the three lines exactly as shown below (for the moment, don’t worry about what these lines do.).
These commands must be submitted to the Console to perform the requested calculations. Commands may be submitted to the Console in a variety of ways:
Put the cursor on a line in the Script Editor and press the
Runicon (); altenatively press
<CTRL>+<Enter>). This will submit that line to the Console and move the cursor to the next line in the Script Editor. Pressing (or
<CTRL>+<Enter>) will submit this next line. And so on.
Select all lines in the Script Editor that you wish to submit and press (or
The RStudio layout after using the first method is shown in the figure above.
The R Script in the Script Editor should now be saved by selecting the
File menu and the
Save item (alternatively, pressing
<CTRL>+S). RStudio can now be closed (do NOT save the workspace). When RStudio is restarted later, the script can be reopened (choose the
File menu and the
Open file ... submenu if the file is not already in the Script Editor) and resubmitted to the Console to exactly repeat the analyses. (Note that the results of commands are not saved in R or RStudio; rather the commands are saved and resubmitted to reperform the analysis.)