Supplement to POL90
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 R: http://www.r-project.org
Install RStudio: https://rstudio.com/products/rstudio/download/#download
Install course packages:
# opens a script to install R packages, do not restart R
source("http://appliedstats.org/POL90_2022_packages.R")
R
, click ‘No’n
and hit
return
RStudio
install.packages('tinytex')
tinytex::install_tinytex()
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.
Hit Command-Spacebar and type Terminal to OPEN the TERMINAL application
Once the Terminal application is open, copy and paste the following text into your Terminal and hit RETURN:
[ -e /usr/local/bin ] || sudo mkdir -p /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/bin
~/Library/TinyTeX/bin/*/tlmgr path add
Open RStudio
Copy and paste this command into the CONSOLE of RStudio (and hit RETURN)
tinytex::install_tinytex()
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")
Error in install.packages : cannot open file 'C:/Users/.../OneDrive/Documents/R/win-library/4.1/file666459c6cb3/distill/help/figures/logo.png': Permission denied
RStudio
as administrator and (2) Under the
Packages
tab, click Install
and change
Install to Library
option to
C:/Program...../R/../library
and select the desired package
to install. See more of this solution at this StackExchange answer: https://stackoverflow.com/a/50787084/893399If you have other issues or questions about TinyTex, see: - https://yihui.org/tinytex/ - Also try emailing your error to omar.wasow@pomona.edu
Once you have installed TeX, if you already had RStudio open, quit and then re-open it.
Once you have installed R, RStudio, knitr, and TeX and restarted RStudio, then, in RStudio do the following to compile a test R Markdown document:
Create new document
File
\(\rightarrow\)
New File
\(\rightarrow\)
R Markdown
Knit to HTML
Knit to PDF
This section is a work-in-progress The instructions below have worked for some students but not others. They will continue to be revised and improved as we identify additional solutions.
Please email me ( omar.wasow@pomona.edu ) any errors you encounter so that this can be refined for future students.
Hit command-space
, type Terminal to open the
Terminal app
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
~/Library/TinyTeX/bin/x86_64-darwin/tlmgr path add
install.packages('tinytex')
tinytex::install_tinytex(force = TRUE)
install.packages('tinytex')
tinytex::install_tinytex(force = TRUE)