The first steps involve setting up R and RStudio, getting acquainted with them, and making sure everything is working.
Install R from https://cran.r-project.org/—it is available for Mac OS, Windows, and Linux. Choose the appropriate link, download, and install.
Install RStudio from https://www.rstudio.com/products/rstudio/download/—choose the free “RStudio Desktop” (all the way to the left). You can run R without RStudio, but I strongly recommend using RStudio (since that is what you’ll be seeing for all examples).
Once you’ve installed R, but before doing anything else, you can install this package. Doing so will also install a number of other imoportant packages.
Occasionally R may ask you questions like “These packages have more recent versions available. It is recommended to update all of them. Which would you like to update?” And you will need to select a response (e.g., type 1 and hit enter to download all updates).
install.packages("devtools")
devtools::install_github("jdbest/psychRstats")
Installing the package will also install all of the tutorials. However, I’ve also written exercises, which you’ll want to download somewhere on your machine. For that purpose, you should follow the instructions below on setting a working directory and then downloading exercises.
You’ll need to make a decision about what will be your “working directory”. The working directory is the folder on your computer where you’ll be storing the exercise files, and where R assumes you’re working. (For example, you might use the “Downloads” folder on most computers is located in your user folder/Downloads, e.g., mine might be in /Users/jdbest/Downloads on a Mac or in C:/Users/jdbest/Downloads on a PC.)
There’s more info on this on the github wiki. You can always return there with questions.
Use the Session > Set Working Directory menu. Navigate to whatever folder you’ll be using for this class. (You might want to use something like /yourusername/psychRstats/labs – but anything is fine so long as you know where it is.) This is the sort of folder that when you go to Finder (Mac) or Windows Explorer (PC), you can find all of the files associated with this class in one place. (If you’re on a shared computer, you may have limited choices. Documents folders are fine!)
Optional: You can permanently set your working directory using the Tools Menu. Go to Tools: Global Options, and then click the “Browse…” under Default working directory. Navigate to the same folder you just set.
If you’re familiar with some coding, you can also set your working directory using the setwd() command—just be sure to enclose the path in quotation marks, e.g., setwd("/yourusername/psychRstats/labs").
(Read more about working directories in R and RStudio.)
To check that you’ve got the right working directory set up, run the following code in the RStudio console (just copy and paste it and then hit enter):
getwd()
Does it say what you expected it to? If not, either ask for help or read through the above again.
Your files will download to “/home/rstudio-user” – if when you run getwd() you don’t get that, run the following code: setwd("/home/rstudio-user").
If you want to download files from the Cloud to your own computer, follow these instructions.
When you have decided on your working directory—even if you’re sticking with "~" (your user folder), you can download the lab exercises. They will all download from a zip file, and all be R Markdown files designed to run in RStudio. You should have downloaded the package before this will work:
psychRstats::download_exercises()
The lab documents will download to your computer in the directory (folder) you defined above—into your working directory. (If you didn’t define it, it’ll download into whatever working directory was the default, usually your user folder.) It may pop up a folder where the file lives.
If you run into any errors, consider looking to the wiki page on troubleshooting for solutions. (You can also scroll up and click “Wiki”.)
All right! Now that you’ve gotten everything installed, run the first tutorial:
psychRstats::lab("01-intro-to-r")
For attribution, please cite this work as
Dainer-Best (2020, Aug. 31). psychRstats: Learning Statistics for Psychology in R: 01: Introduction to R. Retrieved from https://jdbest.github.io/psychRstats/labs/01-intro-to-r/
BibTeX citation
@misc{dainer-best202001:,
author = {Dainer-Best, Justin},
title = {psychRstats: Learning Statistics for Psychology in R: 01: Introduction to R},
url = {https://jdbest.github.io/psychRstats/labs/01-intro-to-r/},
year = {2020}
}