1. Check Working Directory

You must know which working directory you are in. To show your current directory, type below in R console.

getwd()

If you save a dataset later, this is the folder it will be stored at.

To change your working directory, go to File -> Change dir… on top menu.

Alternatively, you can use script to change the working directly

setwd('/Users/nmimoto/Dropbox/GARAGE/IntroR/')



2. R Packages

R comes with tons of free packages that can perform cutting edge statistical analysis. However, since there are so many of them available, R does not install them until you tell them that you need it.

Installing Packages

You only need to install each package once per PC. To install packages, use TOOLS -> INSTALL PACKAGES, or use script

install.packages("MASS")     # installs package called MASS


Loading Packages

Each time you open R, you need to load the package. To load use script:

library(MASS)                # load package MASS (it needs to be installed first)

Note that you don’t need around MASS in library command, but you must have them in install.packages command.

Code Only

### 1. Check Working Directory
getwd()
setwd('/Users/nmimoto/Dropbox/GARAGE/IntroR/')

### 2. R Packages
install.packages("MASS")     # installs package called MASS (once per PC)
library(MASS)                # load package MASS (everytime you open R)