After R installation has completed, point your browser to the download section found through the RStudio web site (https://www.rstudio.com/) and install the RStudio executable appropriate for your operating system:
- Click the
RStudio
icon to bring up the program. - The program initially starts with three tiled window panes, as shown in the following screenshot. If the layout does not correspond exactly to what is shown, the next section will show you how to rearrange the layout to correspond with the examples shown in this chapter:
To rearrange the layout, see the following steps:
- Select
Tools
|Global Options
|Pane Layout
from the top navigation bar. - Select the drop-down arrow in each of the four quadrants, and change the title of each pane to what is shown in the following diagram.
- Make sure that
Environment
|History
|Files
|Plots
andHelp
are selected for the upper left pane - Make sure that
Viewer
is selected for the bottom left pane. - Select
Console
for the bottom right pane - Select
Source
for the upper right pane
- Make sure that
- Click
OK
.
After the changes are applied the layout should more closely match the layout previously shown . However, it may not match exactly. A lot will depend upon the version of RStudio that you are using as well as the packages you may have already installed.
- The
Source
pane will be used to code and save your programs. Once code is created you can useFile
|Save
to save your work to an external file, andFile |
Open
to retrieve the saved code.
Note
If you are installing RStudio for the first time nothing may be shown as the fourth pane. However, as you create new programs (as we will later in this chapter), it will appear in the upper right quadrant.
- The
Console
pane provides important feedback and information about your program after it has been run. It will show you any syntax or error messages that have occurred. It is always a best practice to examine the console to make sure you are getting the results you expect, and make sure the console is clear of errors. The console is also the place that you will see a lots of output which has been created from your programs. - We will rely heavily on the
View
pane. This pane displays formatted output which is run by using the RView
command. - The
Environment
|History
|Plots
pane is sort of a catch-all pane which changes functions depending upon what which tabs have been selected via the pane layout dialogue. For example, all plots issued by R command are displayed under thePlots
tab. Help is always a click away by selecting theHelp
tab. There is also a useful tab calledPackages
which will automatically load a package, when a particular package is checked.
Once you are set with your layout, proceed to create a new project by following these steps:
Create a new project by following these steps:
- Identify the menu bar, above the icons at the top left of the screen.
- Click
File
and thenNew Project
- At the next screen select
Existing Directory
:
- The following screen will appear:
- The
Project working directory
is initial populated with a tilde (~
). This means that the project will be created in the directory you are currently in. - To specify the directory first select
Browse
, and then navigate to thePracticalPredictiveAnalytics
folder you created in the previous steps. - When the
Choose Directory
dialog box appear, select this directory using theSelect Folder
button. - After selecting the directory, the following should appear (Windows only):
- To finalize creating the project, Select the
Create Project
button. Rstudio will then switch to the new project you have just created.
All screen panes will then appear as blank (except for the log), and the title bar at the top left of the screen will show the path to the project.
To verify that the R, outputs, and data directories are contained within the project, select File
, and then File Open
from the top menu bar. The three folders should appear, as indicated as follows:
Once you have verified this, cancel the Open File
dialogue, and return to RStudio main screen.