Starting with R

Setup
R
Published

November 21, 2023

Keywords

R, Positron, 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 Positron (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

Positron

Note

If you have already follow the getting started with Python documentation you shoudl already have positron installed and you can skip this step!

While the R installation includes a basic IDE (think of it as a very plain text editor), we definitely want to use something more refined. While Rstudio has been our favorite IDE for a while we now prefer Positron. Positron is a IDE ( based on a fork of Vs Code) that allows to run and interact efficiently with both R and Python and has become our IDE of choice lately.

Installing Positron is straightforward:

  1. Go to the Positron website

  2. Follow the instructions and download Positron for your operating system

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

Once installed, you can launch Positron. Here it is in all its glory:

The first time you launch Positron, you’ll see a “Start Session” button in the top-right corner. (If it’s not your first time, you’ll instead see a button showing which environment you’re currently using.)

Click it—and voilà!—you’ll get a list of all your R interpreters and Python environments. Pretty neat, right?

Just pick the R interpreter you want to work in (you probably have just one), and the console at the bottom will instantly switch to that setup. From that moment on, any code you run in Positron will use the exact R version and packages installed in it.

That’s it—now any code you run will execute within the environment you selected. Well done!

Flowchart

Installing R packages

Now that we have both R and Positron, 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. In the R console we just activated paste:

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

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 Positron 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 whether all is ok.

Download our test script and run it in Positron. 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 Positron
  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