Setup
In this section we cover all of the start-up activities that you need to complete in order to use RStudio effectively: install the software, prepare your computer to hold the data that you will be using, load the tidyverse
library, and download data that you will use RStudio to analyze.
1 Installing software
In this section, we will install the software that you need to do your work. This includes R
, RStudio
, and a few packages that you will use both throughout any courses you take from us and in your own work.
1.1 Install R
and RStudio
Both pieces of software and free and open source. You can install them on your own computer as you would any other piece of software. In the following, I take you through the steps to install R
and RStudio
on your computer.
1.2 Set your RStudio
preferences
In the following video, I take you through the process of setting your preferences in RStudio
. It’s an extremely complex piece of software, so it’s not at all obvious what the settings should be. This is a very important step, as it will help you to work more efficiently and effectively. I not only go through the steps, but I try to explain why you want to make these changes.
As you gain experience with RStudio
, you will want to return to your settings throughout the Global options
dialog box and see if you want to change anything. The defaults are perfectly reasonable but these options are here for a reason.
2 Getting familiar with RStudio
If you have developed software before, then this software will generally make sense to you. If not, it will feel like a foreign landscape. In the following video, I take you through the major components of RStudio
and how to use them.
3 Installing packages
Packages are bits of software that extend R
’s capabilities. Over 20,000 of them exist. The following video helps you understand packages, how to install them, which ones to install, and how to use them.
If you want to install the packages that are mentioned in the previous video, then copy the following and execute them in the Console
window of RStudio
. You will only have to do this once. But, remember, in order to use the package after installing it, you will have to execute the library()
command for it.
- Basics/everyone
- R Scripting/data manipulation
- Data visualization/graphing
4 Using RStudio
projects
RStudio
projects (not to be confused with R
projects) are the means by which an analyst can organize and share his/her work. The following video explains what projects are, why you should use them, and how to use them.
4.1 Explanation (alternative to the video)
4.1.1 Starting a new project
The following are the steps that you should complete when starting a new project. You might consider printing out this page as a reminder of the steps to take while you are at the beginning of your learning journey.
4.1.1.1 Preparing your computer for data
When you are doing any data analysis project, you have to have a place to put the data (we did that above) and tell RStudio
where to look for data (which we’ll do now).
4.1.1.2 Create a new project subdirectory
Any time that you start a new project, create a folder for it within your overall folder structure. There you will store the data, scripts, and output related to the project. For all but the smallest projects, you may want to set up the project folder with subfolders called /R
(for R scripts), /data
(for data files), and output (for whatever gets generated). You may also want a /docs
subfolder to keep documentation like notes and presentations in.
4.1.1.3 Create a new RStudio
project
After creating the subdirectory, you need to tell RStudio
that you are beginning a new project. You do this with the menu choice File/New Project...
; when the dialog box comes up, choose Existing Directory
and then browse to the directory that you just created.
The wonderful thing about creating this project is that now RStudio
knows where to look for data—i.e., where the working directory has been set. The project will also remember which files you have open, so you can jump right back in after closing RStudio
and returning to the work later on.
If you want to know what the working directory is for R, then go to the Console
and type getwd()
.
4.1.2 Returning to an existing project
After you have gone through all of the pain of starting a new project, subsequent working sessions will be much easier. When you start RStudio
, it will automatically go to the most recent project. If you are starting up RStudio
after working on some other project or with a completely empty RStudio
workspace, then use the menu to fine File/Recent Projects
and choose the name of the project that you want to work on. The project will open, the working directory will change, and the files that you most recently were working on will be open. There’s also a project shortcut menu top right of the RStudio
window.