Starting with R

Setup
R
Published

November 21, 2023

Keywords

R, Rstudio, lme4, lmer, easystats, tidyverse, experimental psychology, tutorial, installation, DevStart, developmental science

R is THE BEST programming language for statistics. We are ready to fight you on this!

We’ll use R extensively throughout the website, especially for statistical modeling, data preprocessing, creating beautiful visualizations, and running complex analyses like mixed-effects models. Whether you’re analyzing reaction times, eye-tracking data, or running sophisticated statistical tests, R will be your best friend. So… on this page, we’ll guide you through installing R and RStudio (one of its best IDEs), plus all the essential libraries you’ll need for our tutorials. Don’t worry – these steps are straightforward and easy to follow.

Tip

We strongly recommend using our interactive flowchart to guide yourself through the tutorials! It will help you follow the setup steps in the right order based on your experience level.
Flowchart

Install R

Let’s start..:

  1. Go to this page (CRAN stands for Comprehensive R Archive Network – it’s the official repository for R)

  2. Download R for your operating system

  3. Run the installer and follow the on-screen instructions (just keep clicking “Next” – the defaults are perfectly fine)

Well… that really was easy! R is now installed on your computer, but we’re not quite done yet.

Flowchart

RStudio

While the R installation includes a basic IDE (think of it as a very plain text editor), we definitely want to use RStudio. This is where the magic happens! RStudio transforms R from a command-line tool into a beautiful, user-friendly interface that makes coding a joy rather than a chore. RStudio offers tons of features that will make your data analysis journey much smoother Maybe this step will be a bit trickier…

  1. Go to the RStudio page (Note: Posit is the company that makes RStudio)

  2. Download RSrtudio Desktop for your operating system

  3. Run the installer and follow the on-screen instructions

Nope – just as easy as before!

Flowchart

Installing R packages

Now that we have both R and RStudio, we need some essential libraries (called “packages” in R). I’ll describe only a few of the main ones here, but more will be installed and covered throughout the tutorials. Core Packages:

  • tidyverse: This is a collection of packages, so when you install and import it, you’re not just getting one library but an entire suite of them. It includes ggplot2 (for stunning visualizations), dplyr (for data manipulation), readr (for reading data), and many more. Perfect for data wrangling and creating beautiful plots. This is probably the most important package ecosystem in R. Explore all the sub-packages to learn more!

  • easystats: A user-friendly collection that makes statistical analysis much simpler and more intuitive. It includes packages for model fitting, reporting, and interpretation. Explore all the sub-packages to learn more!

  • lme4: The go-to package for fitting linear and generalized linear mixed-effects models. Essential for analyzing complex experimental data where you have repeated measures or hierarchical data structures (which is pretty much every psychology experiment).

  • pupillometryR: Specialized package for preprocessing and analyzing pupillometry data. A lifesaver if you’re working with eye-tracking studies.

Installing the packages is extremely easy. There are two ways one with a command int he console:

Paste in the console

install.packages(c("tidyverse", "easystats", "lme4", "lmerTest", "patchwork", "PupillometryR", "fitdistrplus"))

Follow the instructions if any and you are done!!!!

  1. Go to Tools in the top bar

  2. Click install packages

  3. Paste: tidyverse, easystats, lme4, lmerTest, patchwork, PupillometryR, fitdistrplus

  4. Click Install

Follow the instructions if any and you are done!!!!

Additional Packages

We may use additional packages in specific tutorials, but don’t worry – we’ll always mention which ones you need and provide clear installation instructions when the time comes!

Flowchart

Test your installation

🎉 Congratulations! You should now have R and RStudio fully set up with all essential packages!

But let’s make sure everything is working perfectly before we dive into the tutorials. Want to test whether all packages installed correctly and you’re ready to go? We’ve created a test script that checks whterh all is ok.

Download our test script and run it in RStudio. If everything is working properly, you’ll see detailed progress updates, sample results, and a nice completion message with a celebration plot at the end. If there are any issues, the script will try to tell you what is wrong.

📥 Download Test Script

How to use the script:

  1. Download the file above
  2. Open RStudio
  3. Open the downloaded TestInstallationR.R file
  4. Select all the code and run it (or press Ctrl+A then Ctrl/Cmd+Enter)
  5. Watch the magic happen!

If you see the celebration plot at the end, you’re officially ready to tackle all our R tutorials!

Back to top