Skip to main content
Chemistry LibreTexts

1.5: Installing R

  • Page ID
    144260
  • \( \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}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    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
    4. Choose your operating system, download and run the installer

    clipboard_e5e92ec728137dc179d9ae8879aa42dea.png

    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/)
    2. Click on Download
    3. Choose the free desktop "Open Source License" version
    4. Follow Instructions

    clipboard_e02997c40a5e7a58e9e8b019e333aa751.png

    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.

    Identifying Downloaded Packages

    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

    clipboard_e7fdc880be0865bc3ce20e39b6c18949e.png

    Downloading a New Package

    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.

    • Was this article helpful?