4.3 Starting out in R
R is both a programming language and an interactive environment for data exploration and statistics. Today we will be concentrating on R as an interactive environment.
Working with R is primarily text-based. The basic mode of use for R is that the user types in a command in the R language and presses enter, and then R computes and displays the result.
4.3.1 Downloading, Installing and Running R
Download
R can be downloaded from CRAN (The Comprehensive R Archive
Network) for Windows, Linux, or
Mac.
Install
Installation of R is like most software packages and you will be guided.
Should you have any issues or need help you can refer to R Installation
and
Administration
Running
R can be launched from your software or applications launcher or When
working at a command line on UNIX or Windows, the command R
can be
used for starting the main R program in the form R
You will see a console similar to this appear:
While it is possible to work solely through the console or using a command line interface, the ideal environment to work in R is RStudio.
4.3.2 RStudio
We will be working in RStudio. The easiest way to get started is to go to RStudio Cloud and create a new project.
The main way of working with R is the console, where you enter commands and view results. RStudio surrounds this with various conveniences. In addition to the console panel, RStudio provides panels containing:
Studio is divided into four “panes.” The placement of these panes and their content can be customized (see menu, Tools -> Global Options -> Pane Layout).
The Default Layout is:
- Top Left - Source: your scripts and documents
- Bottom Left - Console: what R would look and be like without RStudio
- Top Right - Environment/History: look here to see what you have done
- Bottom Right - Files and more: see the contents of the project/working directory here, like your Script.R file
For these instructions code will appear in the gray box as follows:
fake code
To run the code you can copy and paste the code and run it in your
RStudio session console at the prompt >
which looks like a greater
than symbol.
> fake code
The code can also be added to an R Script to be run.
When the code is run in RStudio the console prints out results like so:
[1] Result
In this tutorial results from code will appear like so:
## [1] Result