Installing R and RStudio
Introduction
R and RStudio are open source software that you can download and install on your own computer for free. In lab this semester we will use R to analyze and plot data from the watershed. Some of the computations will be done on your own computer, and some will be done on the high performance cluster.
R is a programming language and computational environment that was designed for statistical computations (but it can do much more). RStudio is an integrated development environment (IDE) for R. RStudio has several features that make it easier to interact with R and view output such as plots and the results of statistical tests.
Installing R and RStudio on a Mac
- Download the latest version of R for your operating system from CRAN https://cran.r-project.org/
- If you are using a Mac you need to know whether you have an Intel or apple silicon processor. If you do not know which one you have, go to the Apple menu at the top left corner of your desktop and select ‘About this Mac’. Under processor (in the overview) it should list the type of processor you have. Select the correct version of the installer (.pkg file) for your processor.
- Install R
- You just need to double click the installer file. You should probably accept all of the default options.
- Download RStudio Desktop from https://posit.co/download/rstudio-desktop/
- Choose the free Open Source Edition
- Click through a few things that say things like Install RStudio. Then it should suggest the right version of the installer for your operating system
- Install RStudio
- Double click on the installer
- Drag the RStudio icon into your Applications folder (in the window that pops up)
- You will probably want to accept the default options
- Open RStudio
- The easiest way to do this is to use the spotlight search - type command + space bar (holding down both at the same time)
- Type RStudio into the search bar and hit return
- Try a calculation
- When you open RStudio you will see the R console (and other things)
- At the > prompt type 2+2 then return
- It should give you an answer
Installing R and RStudio for Windows
- Download the latest version of R for your operating system from CRAN https://cran.r-project.org/
- Follow the ‘base’ link and download R for Windows.
- Install R
- Double click the installation file and accept the default options.
- Download the latest version of Rtools for Windows
- Follow the ‘Rtools’ link, then follow the link for the latest version of Rtools. Next click on the link for the ‘Rtools43 installer’ (43 may be replaced by a larger number for later versions)
- Install Rtools
- Double click the installation file and accept the default options.
- Download RStudio Desktop from https://posit.co/download/rstudio-desktop/
- Choose the free Open Source Edition
- Click through a few things that say things like Install RStudio. Then it should suggest the right version of the installer for your operating system
- Install RStudio
- Double click on the installation file
- Select the default options
- Open RStudio
- From the Windows Search or the Windows menu find RStudio and open it
- Try a calculation
- When you open RStudio you will see the R console (and other things)
- At the > prompt type 2+2 then return
- It should give you an answer
Rosetta 2 on M1-M3 Mac
Sometimes you need to install Rosetta 2 on an M1-M3 Mac to get R to work properly.
- Open a terminal window.
- Copy and past the following command into the terminal and hit ‘return’:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
Updating R and RStudio
To update R, you simply follow the instructions above for installing R for your operating system. You just need to follow steps 1-2.
To update RStudio, Mac users should follow steps 3-4 from above and Windows users should follow steps 5-6.