So you want to make an R Markdown file using pdf rather than the html used by everyone else? It gets a little more complicated at this point but stay with me! Many first time users of R Markdown find that html runs fine but pdfs fail and they get a lot of confusing and worrying error messages that they feel lost debugging. For that reason I’ve compiled you the following document showing some of the debugging tips created to aid you in your quest.
Check that you are all up-to-date with your R installations and packages.
You can use the code:
to find out what version of R you have installed on your computer. Then you can check your version against the ‘news’ section at the ‘official R website’ to see if it matches.
If it doesn’t, then you can install the package ‘installr’ and use the function ‘updateR()’ to obtain the latest version:
#install the package
install.packages('installr')
#load the package
library(installr)
#update R to latest version
updateR()If you already had the latest version, you may want to check that your packages are all updated:
RStudio interacts with a different typesetting system called LaTeX to produce pdfs. If your computer won’t run pdfs you may have to download another installer called MikTeX (windows PC) or MacTeX (Mac).
Follow the instructions on the web pages provided for installation.
Check that you have the ‘tinytex’ package installed. This installs a relevant custom LaTeX distribution for your R.
However, even after you have installed the package you may still find errors when you attempt to knit your pdf. You may be able to get around this using the function ‘install_tinytex’ from ‘tinytex’.
Knit your pdf for final success. Make sure the output in the YAML header is set to ‘output: pdf_document’ and run, run, run this coding experiment :).
Still got issues? DOH!-n’t worry! Everyone has an individual computer but most people will have an issue that has been encountered before.
You can try going through the ‘tinytex debugging page’ or you can try stackoverflow for some answers. Google is also your friend. Search any error messages that crop up and you might find some relevant advice for your issue.