Installing R & RStudio
Overview
For this course, we will use the R
programming language and the RStudio
IDE for manipulating data and creating data visualizations.
To Do
Due by class time on the first day of class.
Tasks
The first step for this course is to install and configure some software. If you have these installed on your computer, you will need to ensure you have the correct versions of software and libraries installed.
- Download and Install
R
- Download and Install
RStudio
- Configure
RStudio
- Install
R
libraries/packages needed
Optional Readings
If you need a refresher on the RStudio IDE, consider this intro to R.
If you need a refresher on R Markdown, consider this link on working with RMarkdown.
Downloading Software
Determining the version of your computer’s operating system
Your version of operating system will dictate which version of R to download and install. Make note of your computer’s operating system.
Windows systems are easier and Windows 10 and 11 operating systems will both use the same R versions.
Macs are somewhat more complicated. The version depends on your cpu. Visit this link to determine.
There will be two cpu options, Intel 64-bit for macOS 10.13 or Apple silicon arm64 for macOS 11 and higher.
Cloud Options:
If you do not have a laptop (let me know) or do not have 5GB of hard drive space available on your computer, you might consider a cloud version of the software. One is maintained by Posit (formerly RStudio) and the other is maintained by CMC.
Posit (25 free compute hours a month – make time out)
Remote Desktop Protocol (No limit on compute hours) (contact me if interested). This is managed by CMC but may not be reliable.
Downloading R
Once you know your processor, navigate to https://cran.r-project.org/ and in the “Download and Install R” section, select your operating system. You can also select from below and follow the indented sections that follow.
Windows users should select the base version of R
and download version 4.4.1 (no other version) to your computer. If this version is not on the main page, go to the “Other Builds” section and select “previous releases” and download the correct version.
Mac users should download either R-4.4.1.pkg or R-4.4.1x86_64.pkg version depending on the cpu noted earlier. Do not download any version other than 4.4.1 and please do not update throughout the semester.
Downloading RStudio
Use the urls below to download RStudio
and save it to the same directory location on your computer as you saved R
.
Windows 10/11: https://download1.rstudio.org/electron/windows/RStudio-2024.04.2-764.exe
MacOS 12+: https://download1.rstudio.org/electron/macos/RStudio-2024.04.2-764.dmg
MacOS 10.15-11: https://s3.amazonaws.com/rstudio-ide-build/electron/macos/RStudio-2023.09.1-494.dmg
Linux: go to https://posit.co/download/rstudio-desktop/
Note: If you have a 32bit operating system, you will need to install an older version: https://www.rstudio.com/products/rstudio/older-versions/
Installing R and RStudio on your Computer
Installing R (then install RStudio)
Installing should be easy and you can accept all of the defaults although the desktop icons are not needed, especially for R
because you will never need it; RStudio will find R for you. You can follow these videos for simple installing.
PC: How to Install R and R Studio on Windows 10/11
Mac: Installing R and RStudio on a Mac
Note: If you leave the desktop icon for R
, you can remove that later. You will never need it because RStudio will find R
for you.
Additional Step for Mac Users:
Download and Install XQuartz
Some functions in R require an “X11 Server” and/or libraries associated with an X11 server. Apple does not provide this software with OS X anymore so unfortunately you have to do it on your own via a third-party application called XQuartz for OS X 10.9 or later.
Use the url below to download the XQuartz file and save it to your computer. Follow the same install instructions as above for installing the XQuartz file.
For macOS 10.9 or later, download this XQuartz file and save it to your computer and install: https://github.com/XQuartz/XQuartz/releases/download/XQuartz-2.8.5/XQuartz-2.8.5.pkg
Verify that RStudio is communicating correctly with R
Launching the RStudio application.
If RStudio
and R
are communicating correctly, you should see an RStudio
window open with the R
console opened which should look similar to that shown below. Your R version should be listed at the top of the console (4.4.1).
Configuring RStudio
A. Go to Tools > Global Options under the General + Basic Tab
R Sessions > R version: There should be a path to the installed R
version listed if you installed R
before RStudio
. You should not need to change this unless you have another version installed on your system. If you do have multiple versions, browse to version 4.4.1. Do not update R
or any libraries during this course.
Mac Users may not see an R
version and may only see the following:
If you are concerned that R
may not be there, type 2 + 2 into the R
console and press Enter/Return. If the solution is returned, then R
is installed.
B. Other options: Check the other check boxes as indicated in the images below.
GENERAL (basic):
CODE (editing):
CODE (display):
CODE (saving):
CODE (completing):
CODE (diagnostics):
CONSOLE:
APPEARANCE:
Appearance is one of preference. You can try out different RStudio Themes and Editor Themes to see what you like. Due to a degenerative eye disease which includes photophobia as a symptom, I am able to use only dark-mode editor themes. In order to help you with your code, if a dark-mode theme does not affect you negatively, please use one. Videos will use the editor theme called Made of Code because this theme appears to provide me with the best visual contrast among functions and objects and does not cause me any discomfort. This theme is available in the start-project repository which is used in the module on Project Management. The Theme can also be found here. A native RStudio theme that I have used in the past is Merbivore. The font I use is Lucida Console.
Please use a theme that you find most comfortable using. Please just understand that my disability may prevent me from reading your screen in class if your theme is not dark. You may just have to verbatim explain what is on your screen so that I can best help you.
The installation process will take quite some time (15 minutes) especially depending on your computer so do this at a time you do not want to use your system. Plug in your computer and take a break. Take a break and do something else.
OTHERS: We will address in class as appropriate.
Installing R libraries/packages
After you have completed installation, you will need to install different libraries that we will use a various times over the course of the semester. Rather than installing the libraries manually, (1) copy the code below, (2) paste it into the RStudio Console window at the >
prompt (see image), and then (3) press enter to execute.
Copy this code:
source('https://raw.githubusercontent.com/slicesofdata/dataviz24/main/src/psyc167_libraries.R')
Paste the code into your R console at the >
prompt:
Press return/enter