View on GitHub

rminr

Research Methods in R

Using RStudio

Andy Wills

A big part of psychology is collecting data about people, visualizing it (graphs etc.), and drawing conclusions. RStudio, like Excel, is computer software that helps us to do that. RStudio is rapidly becoming the standard tool for serious data analysis in psychology, because it’s powerful, relatively easy to use, and free. In these series of worksheets, you’ll learn the basics of how to use it.

Getting started

Using your web browser, go to an RStudio server and log on, using the username and password you have been given.

NOTE: We strongly recommend using the Firefox web browser to access RStudio. If you are having problems and you’re using something other than Firefox, the first thing to try is to download and install Firefox on your machine and see if it fixes the problem. Firefox is free and open source.

If that works, you should see something like this:

RStudio on first opening

We’ll go through what it all means in a bit. But, first, we’re going to…

Create a new project

RStudio uses projects to help you keep your work organized, and to make sure you have a record of your analyses. You should start a new project each time you start a new module in your degree. Here’s how to create a new project:

  1. At the top right of RStudio, you will see a little blue cube, with the text “Project: (none)”. Click on this, and select “New project”.

RStudio without a project open

  1. Now click “New Directory”

Project dialog #1

  1. Now click “New Project”

Project dialog #2

  1. Next, type in a name for the project that makes sense to you in the “Directory name” box. (Plymouth University students: Use the code of the module you’re currently studying as your project name, e.g. psyc519**). Then click “Create project”.

Project dialog #3

  1. Now, create a R script. An R script is a record of the analyses you have done. You create an R Script by clicking on the white plus sign on a green background (see below), and then clicking on “R Script”.

Script menu

If everything worked well, your screen should now look like this:

Project created

You should be able to see four parts:

  1. The Script window - This is the rectangle on the top left. This is where you will tell R what to do. It only does what you tell it.

  2. The Console window - This is the rectangle on the bottom left. This is where R prints the answers to your questions.

  3. The Environment window - This is the rectangle on the top right. It’s where R keeps a list of the data it knows about. It’s empty at the moment, because we haven’t given R any data yet.

  4. The Files - This is the rectangle on the bottom right. This is a bit like the File Explorer in Windows, or the Finder on a Mac. It shows you what files are in your R project.

Please now move on to the next worksheet.