Now we’re going to ensure R Markdown works the way we want. A key functionality we need is being able to “knit” our report to PDF format.
With the newest versions of RStudio, you may be able to knit to PDF without doing anything special first.
Let’s give this a try:
Step 1: While in RStudio, select the “+” dropdown icon at top left of RStudio window, and select R Markdown. RStudio may at this point install a bunch of things, and if so that’s ok. It may also ask you to install the
rmarkdown package.. if it does, do so!
Step 2: A window will then appear and you can replace the “Untitled” with something like “Test”, then select OK.
Step 3: This will open an R Markdown document in the top left panel. Don’t worry about all the text in there at this point. What we want to do is test whether it will “knit” (render) the document to PDF format.
Step 4: Select the “Knit” drop-down icon at the top of the RStudio window, and select “Knit to PDF”. RStudio will ask you to first save the markdown file (save it anywhere with any name for now), then it will process the markdown file and render it to PDF.
If this worked, great!! You can ignore the next section here. If it didn’t work, then proceed to this next section:
If the preceding steps did not result in you being able to knit your markdown document to PDF, then do this:
tinytex package by typing this code into the command console of RStudio:
Then, once that has installed successfully, type the following:
RStudio will take a minute or two to install a bunch of things. Once it’s done, we’re ready to try knitting to PDF.
Recall you only need to install a package once! And this should be the last time you need to deal with the
tinytex package (you won’t need to “load” it in future), because now that it’s installed, its functionality works in the background with RStudio.
Now go back to the steps 1 through 4 above to try knitting your markdown document to PDF.
In a future tutorial we’ll discuss how to use R Markdown as part of a reproducible workflow.