Installing R, RStudio, R Markdown, Latex

Supplement to POL90

Team 90 pol90.com (Pomona College, Politics)http://pomona.edu/academics/departments/politics
2022-06-07

For POL90, we require students shift away from word processors like Microsoft Word and use a workflow that involves R and a formatting language called R Markdown (as is done in some other stats classes). The two languages are glued together with another language called knitr. Certain kinds of advanced typography, like formulas, rely on yet another language called Latex. Installing and configuring all of this will impose a modest learning curve at the start but will make life much easier down the road.

The basic advantage of R + R Markdown + knitr + Latex is that you can easily braid together your prose, R code, formulas and R output (e.g., plots and tables) in a single document. This not only saves time and makes life easier by reducing the number of files that need to be managed, it also helps with creating better research such as when you write JPs or Senior Theses (we’ll discuss this more in class).

To get set up with R + R Markdown + knitr + Latex, please do the following before class:

Install software and packages

# opens a script to install R packages, do not restart R 
source("http://appliedstats.org/POL90_2022_packages.R")

If necessary, install LaTeX

TinyTeX

install.packages('tinytex')
tinytex::install_tinytex()
  1. To test if the installation worked, see Test your installation below:

TinyTex Issues

  1. If, when installing TinyTex, you get an error like the following:

The directory /usr/local/bin is not writable. I recommend that you make it writable. See https://github.com/yihui/tinytex/issues/24 for more info.

[ -e /usr/local/bin ] || sudo mkdir -p /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/bin
~/Library/TinyTeX/bin/*/tlmgr path add
tinytex::install_tinytex()
  1. If you run tinytex::install_tinytex() and get an error like this:
curl failed to verify the legitimacy of the server       

Try the following slight modification:

tinytex::install_tinytex(version = "2021.10")
  1. For Windows users, if you get an error like this:
Error in install.packages : cannot open file 'C:/Users/.../OneDrive/Documents/R/win-library/4.1/file666459c6cb3/distill/help/figures/logo.png': Permission denied

If you have other issues or questions about TinyTex, see: - https://yihui.org/tinytex/ - Also try emailing your error to

Alternate ways to install LaTeX

Test your installation

Troubleshooting

For students who took other stats classes:

Mac

  1. Hit command-space, type Terminal to open the Terminal app

  2. Copy and paste the following text in to the command line prompt in the Terminal app and hit return

sudo chown -R `whoami`:admin /usr/local/bin
  1. Copy and paste the following text in the Terminal app and hit return.
~/Library/TinyTeX/bin/x86_64-darwin/tlmgr path add
  1. Try to run the following commands in R:
install.packages('tinytex')
tinytex::install_tinytex(force = TRUE)

Windows

  1. Attempt to uninstall MikTek
  1. Try to run the following commands in R
install.packages('tinytex')
tinytex::install_tinytex(force = TRUE)