Chapter 2 Installing R and R-Studio

2.0.1 Instructions for installing R:

  1. Go to this web page: http://cran.stat.ucla.edu/
  2. Under the “Download and Install R” heading, select your operating system (Windows, Mac, Linux).
  3. The directions diverge at this stage, depending on your OS.

2.0.1.1 For Mac, do the following:

  1. Under the “Latest Release” heading, select the top “.pkg” link. Save the file to your computer.
  2. This is the basic installer file.

2.0.1.2 For Windows do the following:

  1. Under the “Subdirectories” heading, select the top “base” link. Save the file to your computer.

  2. This is the basic installer file.

  3. Download and open the installer file. Now, just follow the instructions to set up R. The default settings are fine. No need to open the program yet.

  4. Now, we’re going to download R-Studio, which is the user interface that makes R faster and easier to use. It’s an integrated development environment (IDE)

  5. Once you have R-Studio, you won’t need to open the “base R” GUI anymore, since R-Studio does this for you.

2.1 Instructions for installing R-Studio:

  1. Go to this web page: https://www.rstudio.com/products/rstudio/download/#download
  2. Under the Installers for Supported Platforms header, select your operating system (Windows, Mac, Linux).
  3. Download and open the installer file and follow the instructions. The default settings are fine.
  4. Once R-Studio is installed, go ahead and open the program from your applications list (Start Menu/Launchpad/Desktop).

2.2 Setting up your workspace: Rstudio Projects

First, we’ll set up an R project, a method for managing your work within RStudio. RStudio projects allow you to keep all folders and files associated within a given project together. The project will automatically control your working directory.

To do this: Create a new R studio Project: File -> New Project -> choose directory and project name

2.2.1 Loading necessary “packages” for managine files and cleaning data

Load the here package and tidyverse package in your script to help with working directory and file paths. We’ll use this a little.

If you don’t have them, you’ll have to install them.

install.packages("tidyverse")
install.packages("here")

To load the necessary packages so you can use them, you’ll have to run the commands below in each new R session.

library(tidyverse)
library(here)

# check your working directory

here()
## [1] "C:/Users/katzd/Desktop/Rprojects/Rasch_BIOME/DBER_Rasch-data"

2.3 Setting up the working directory

To make life easier, we’ll follow a general file/working directory structure. There are many ways to set up a working directory, but a simple and easy way to do this involves creating files for your data (sometimes with a subdirectory or new directory for cleaned or altered data), the scripts you’ll use for running analysis, and the resultant output and plot.

So, in the same directory (aka, folder) as your new RStudio project:

  1. Create a folder called scripts
  2. Create a folder called data
  3. Create a folder called output
  4. Create a folder called plots