# 1.5: Installing R

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$ $$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$ $$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$ $$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$$$\newcommand{\AA}{\unicode[.8,0]{x212B}}$$

## What is R?

R is a free and open source programming language initially developed by Ross Ihaka and Robert Gentleman of the University of Auckland in 1993 and now maintained through the R-Project. It is a statistical computing program that supports graphical analysis, data mining and machine learning activities that we will be performing in this class. There is an extensive R developer community that have created over 15,000 additional packages that are available at the Comprehensive R Archive Network (CRAN).

Although we can run all our programs from within R, we are also going to install RStudio, which in an Interactive Developer Environment (IDE) for R. IDEs are code development environments that have a variety of useful features that make it easier to experiment around to both learn and test your code. Figure 1.4.2 shows the RStudio user interface.

## Installations

### Install R

1. Go to Project R (https://www.r-project.org/)
2. Choose CRAN download and this will take you to mirror sites across the planet (https://cran.r-project.org/mirrors.html)
3. Choose a mirror site near you

Figure $$\PageIndex{1}$$: Download options at CRAN (Comprehensive R Archive Network)

### Install R Studio

In this class we will use R Studio, which is an IDE (Integrated Developer Environment), where

1. Got to RStudio (https://www.rstudio.com/)
3. Choose the free desktop "Open Source License" version

Figure $$\PageIndex{2}$$: The RStudio IDE. Note, the top of the IDE has a toolbar that allows you a variety of functions and you can collapse the blocks and resize them to fit your needs.

### Install R Packages

Throughout this course you will need to install R Packages and so it is good to go over it now, at the very beginning. Some packages come with the default download and others you need to install from CRAN. But even the ones that come with the default installation of R need to be installed, as otherwise they would use up too much memory.

library() identifies available packages

To see what Packages you have installed go to the editor and use the library() function. Note as you type, the IDE provides a list of options, and if you hover over "library", it places the syntax for that function into an overlay. If you click F1 while hoovering it places the library help commands into the bottom right block, and if you click on the word "library" it is inserted into the editor with parenthesis. Once you click library() you will get a list of all available packages

install.packages("package name") - this command will download a package from CRAN to your computer. Note, this command uses parenthesis.

#### Activating a Package

library(package name) - this command will activate your package that has been downloaded so that you can run it in R. Note, this command does not use parenthesis.

Note on term "Library" is confusing: What you have is a library of packages on your own computer, and the command library(package name) is looking into the library for the package, and if it is there, it is activating the package. The package is not a library.

### Optional Example: R Commander

If you are new to R you may find R Commander to help you learn commands. This is a package that gives an interface like Excel or Google sheets. Although it will not work for many of the things we are using in the class, it can save you time if you need to quickly learn how to make a scatter plot, or something like that. R Commander is not part of the R download, and so you will need to install and activate. So you may wish to perform the following tasks:

1. library() - scroll through the packages in your library, note Rcmdr is not there
2. install.package("Rcmdr") - this goes to CRAN and installs R Commander
3. library() - scroll through the packages in your library, note Rcmdr is there.
4. library(Rcmdr) - vola, you have an interface like Excel or Google Sheets. Note, if you perform a task, Rcmdr shows you the code it uses.

1.5: Installing R is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.