Installing Software
Table of contents
Introduction
The goal is to create the capability on one’s computer to conduct and communicate reproducible data analysis using modern, open-source, and current software tools.
Learning Outcomes: After completion, students should be able to create a functioning environment for literate programming by installing:
- Base R
- The RStudio Integrated Development Environment (IDE)
- Select R “packages” of software
References:
- RStudio IDE Cheat Sheet. (July 2023)
- Quarto Guide
C Install the Software
C.1 Install Base R
- Install R from the Comprehensive R Archive Network (CRAN): https://cran.r-project.org/
- Choose the appropriate operating system and follow the instructions to “choose your preferred
CRAN mirror
”. - Select a site close to your location, e.g., USA Hoobly Classifieds, Pittsburgh, PA, https://cran.mirrors.hoobly.com/
- Choose the latest version for your computer operating system (OS).
- If Mac OS, choose R 4.3.2 “Eye Holes” released on 2023/10/31 (or higher) for your operating system, download the install file and install as usual for a new application.
- If Windows, choose Base and then choose R 4.3.2 “Eye Holes” released on 2023/10/31 (or higher) and follow the installation instructions
- You should now be able to find an R application with the logo on your computer.
- We will not use that interface (except for rare troubleshooting).
- We will use Posit’s much more user-friendly and capable RStudio Desktop Integrated Development Environment (IDE) and it is also free.
C.2 Install the Free RStudio Desktop
- Posit’s Rstudio Desktop is a highly capable Integrated Development Environment (IDE) designed to greatly increase the ease and efficiency of programming in R.
- Once you have it installed, it has many options you can tailor to support your programming style.
- Go to the RStudio download site at: https://posit.co/download/rstudio-desktop/
- Click on Install RStudio Desktop
- This you get you the free desktop version (not the pro).
- Your version should be at least 2023.09.1 Build 494 or higher.
- Download and install.
- Recommend moving the RStudio Application to your Mac Dock or Windows Task Bar.
C.3 Open RStudio Desktop
- Start an RStudio session by clicking on .
- When you first open up RStudio Desktop, it should look something like this:
- Go to the
Console Pane
. The blinking cursor at the bottom to the right of the “greater-than” or “right arrow>
is called the prompt. - You type in commands after the prompt and then hit the enter or return to execute the command.
- If you make a mistake, use the up-arrow key to cycle through previous commands till you get the one you want so you can correct it.
- You can create new files using the New Files button or the
File/New File
on the top menu. - When you are ready to convert your file. make sure it is saved and click on the Render button for .qmd or the knitr button for .rmd.
C.4 Quarto
- Quarto is a multi-language, next-generation version of R Markdown from RStudio, and includes dozens of new features and capabilities while at the same being able to render most existing Rmd files without modification.
- The Command Line Interface version of Quarto comes built in with RStudio Versions after July 2022 so it should now be installed on your computer.
- You can also install the {Quarto} package by going to the console prompt and entering
install.packages("quarto")
.
C.5 Install the R package for R Markdown
- The R Markdown package is a bundle of software (think of it as an add-in or app) that adds the ability to use R Markdown language to format your documents.
- You can use R Markdown tags to format Quarto documents (.qmd) or older .Rmd R Markdown documents.
- See Tutorial: Hello, Quarto!
- You can install the R Markdown from CRAN using RStudio.
- Go to the RStudio console prompt and type
install.packages("rmarkdown")
and then hit enter or return
C.6 Install \(\LaTeX\)
- \(\LaTeX\) is a high-quality typesetting system designed for the production of technical and scientific documentation.
- \(\LaTeX\) provides many features for embedding mathematical formulas or notation into your document.
- RStudio will use \(\LaTeX\) to convert .qmd or .rmd files to PDF files.
- If you did not install Quarto, you will need to install a version of \(\LaTeX\).
- A full \(\LaTeX\) install is quite large so there is a reduced version of \(\LaTeX\) we can use with RStudio in a package called {tinytex}.
- To install the {tinytex} package, type the following two commands in the R console prompt:
install.packages("tinytex")
tinytex::install_tinytex()
- If you get an error while trying to install tinytex, try manually installing the complete product (it will take a while):
- For Windows users, go to http://miktex.org/download
- For Mac OS users, go to https://tug.org/mactex/
- For Linux users, go to https://www.tug.org/texlive/
- Close RStudio and reopen.
- You will need a working version of \(\LaTeX\) to convert .qmd or .rmd files to PDF.
D Configure RStudio
There are a number of options in RStudio you can configure using RStudio Preferences
or on Windows/Macs the menu item for Tools\ Global Options...
.
Suggest considering the following:
D.1 General/Basic
- R Sessions
- If this is the only course or work for which you are using R this semester, change the default directory to your course directory.
- Check Restore previously open documents at startup.
- Save Workspace
- By default RStudio will automatically save your workspace (a bunch of leftover stuff) when you exit it and restore it when you reopen.
- This might streamline your work but it is bad for reproducibility.
- You might unintentionally be using the results from code you ran in a previous session (which you no longer can view and may not remember so you can’t reproduce).
- To change this option.
- Uncheck
Restore .RData into workspace at startup
. - Change
Save workspace to .RData on exit
toNever
.
- Uncheck
- By default RStudio will automatically save your workspace (a bunch of leftover stuff) when you exit it and restore it when you reopen.
D.2 Code/Editing
- Check (turn on) the following if not already on:
- Insert matching parens/quotes
- Use native pipe operator
- Soft-wrap R Source Files
D.3 Code/Display
- Check (turn on) the following if not already on:
- Rainbow Parentheses
D.4 Appearance
- Change Font Size to one you prefer. You can always adjust on the fly with
CMD +
orCMD -
(or CTRL on Windows)
D.5 R Markdown
- Check Use Visual Editor as the default for new files if you like using the visual editor.
E RStudio Projects
RStudio Projects are a feature of the RStudio IDE that simplify the set up of your RStudio environment for working with multiple files that are part of the same logical project.
An RStudio Project is aligned to a single folder or directory on your computer and encompasses all subfolders/subdirectories underneath it.
When you open an RStudio Project, RStudio will automatically set up your console workding directory, your files pane, and your terminal pane prompt to be in the top level folder of the RSTudio project.
If you are working with a Git Repository, RStudio Projects should align to the repository and can help you do common Git and GitHub functions using the Git Pane.
You can create new projects or turn an existing directory into a project using RStudio.
See RStudio Projects for more help on creating and using RStudio Projects for more efficient operation with R.
F Conclusion
- You should now be able to install the software you need to:
- Start an RStudio session by clicking on .
- Use RStudio to create and save a Quarto or R Markdown file to a folder on your computer.
- Use RStudio to render/convert your file to PDF or HTML formatted output document in a folder on your computer.