This document will help you complete the following steps:

  1. Updating R
  2. Install LaTeX.
  3. Create a new RStudio Project.
  4. Compile the R tutorial contained in dominicks.Rmd to test your installation.

If you need help, you may contact KIS at 847-467-2100 (Global Hub) or 312-503-0159 (Weiboldt) or by email at . They have tested these instructions and should be able to help. Please include a screenshot of any errors you encounter.

1 Updating R

Follow these steps to ensure that you have the latest version of R and that all other packages are up-to-date.

  1. Visit the R website to download the latest version of R for your operating system. Assuming you already have RStudio installed, you should be able to install the latest R version on top of your existing version without needing to do anything else.

  2. Updating R itself does not update all the packages used by R—it only updates the “base” packages within R. We want to make sure that any additional packages you have are up-to-date, too. The easiest way is using the menu in RStudio, by going to “Tools|Check for Package Updates…”, as in the figure below.

    Click on the “Select All” button and then click on the “Install Updates” button. You should see output in your console window that shows R downloading and installing the necessary updates.

    Note: There is a chance that you will see a prompt in blue text in the console window asking “Do you want to install from sources the package which needs compilation?” Type “no” and hit enter.

Update R packages

Update R packages

2 Install LaTeX

It is necessary to install LaTeX in order to create pdf files.

If you already have a version of LaTeX installed, you should skip the remainder of this section.1

If you do not have LaTeX installed, follow these instructions.

The console window in RStudio

The console window in RStudio

  1. Launch RStudio and place your cursor in the console window, as in the figure.

  2. In the console, enter the appropriate commands for your operating system:

    • Windows: Enter these two commands, pressing “Enter” after each.
    install.packages('tinytex')
    tinytex::install_tinytex()
    • Mac OS X: Enter these two commands, pressing “Enter” after each:
    install.packages('tinytex')
    tinytex::install_tinytex(dir='~/.TinyTex') # That's a tilde, not a dash
  3. Installation will take some time, perhaps 10 minutes. As the command executes, pay attention. Two error messages might pop up. You can click to dismiss them. When the installation completes, you have successfully installed LaTeX.

  4. Restart RStudio before continuing to the next section.

3 Create a new RStudio Project

RStudio makes project management easier. For this reason, we strongly recommend that you create a new RStudio project for each course. This will help you manage all the code and data associated with a particular course.

To create a new project in RStudio:

  1. From the File menu, select New Project.
  2. Click New Directory.
  3. Click New Project.
  4. Type the name of the new folder in which you want to store all course assignments and data. RStudio will automatically create this folder for you. For example, you might call this folder retail-analytics-assignments.
  5. Specify the folder in which RStudio should create this project folder.
  6. Click on Create Project.

RStudio will create the project and open it. Information about the project is stored in the project directory in a new file called retail-analytics-assignments.Rproj. The easiest way to open the project in the future is to double click on this .Rproj file.

You should store files for each course within this project directory. When you work on these files, you should first open the project in RStudio.

4 Run the Tutorial

You will run your first R program to make sure everything is set up properly and to automatically install some additional packages. Make sure you are connected to the Internet when you complete this step.

  1. Download two files from Canvas and store them in the course project directory:
    • dominicks.Rmd - This file is an R Markdown document. When saving the file, make sure it has a .Rmd extension.
    • dominicks_oj.xlsx - Input data for dominicks.Rmd.
  2. Open the course project in RStudio. There are two ways to do this.

    • Open RStudio. Using the menu, select File|Open Project and navigate to the project directory to select the .Rproj file.
    • Double click on the .Rproj file, which should open RStudio and the project.

    Once you open the project, your RStudio window should look like this:

  1. In the Files window on the lower right, click on the dominicks.Rmd file. Alternatively, you can open this file using File|Open File. Note the Files pane shows us that both dominicks.Rmd and dominicks_oj.xlsx are in project folder.

  2. When you open dominicks.Rmd, you might see an RStudio window pop-up asking to “Install Required Packages”. If so, click on Yes.

  3. Click the “knit” button, as shown in the image below. RStudio may again ask your permission to install necessary packages, and if so, allow it to do so. When it finishes installing packages, you may need to click the “knit” button a second time.

  1. After a few moments, you will see output generated in the R Markdown window in the lower left of RStudio. This means RStudio is compiling the document. You may also notice some temporary files being created and removed in the project folder. When it is finished, the message “\(\color{red}{\text{Output created: dominicks.pdf}}\)” should be displayed at the bottom of the R Markdown window, and there should be a new file, dominicks.pdf, in the project directory. This file is a standard PDF document that you can open with any PDF viewer, move to a different directory, send to a friend, etc. After the PDF is created, a window will automatically open to display it.

  1. The PDF is a tutorial on using R to analyze data on orange juice sales at Dominicks Fine Foods (a now defunct grocery store in Chicago). Scroll to the end of the document and you should see a message titled “Package Installation Report,” listing the packages that were installed or that none were required.

If dominicks.pdf is created and the first page looks similar, that’s it! You have compiled your first R Markdown document and all the packages are working properly. This includes the installation of the tidyverse collection of packages, which handle data manipulation, plotting, and more. You also installed a small version of , which is a suite of programs that collectively produce PDF documents. You will never have to run any of these programs yourself. Rather, RStudio uses , behind the scenes, as needed, to create PDF documents from R Markdown documents.

If you are not connected to the Internet, you will see a message at the bottom of the first page of the PDF such as “Warning: unable to access index for repository…” Make sure you are connected and then click on the “knit” button again.


  1. You can check if you have LaTeX installed by running this command in the RStudio console: system("pdflatex --version"). If you see an error message, you do not have LaTeX installed.



Copyright © 2018 Brett Gordon and Robert McDonald. All rights reserved.