<- c(
markdown_practice "rmarkdown",
"tinytex",
"tidyverse",
"knitr",
"remotes",
"gapminder",
"shiny",
"flexdashboard",
"here")
install.packages(markdown_practice)
Topic 5: Going Further with R Markdown
You need certain R packages for using R Markdown and also for carrying out this tutorial. The following instructions will help to get you set up and ready to go.
Install packages
Open RStudio and copy-paste the lines below into the console and press Enter:
Note: The steps above might take a wee while to run, so don’t worry if it looks like it has momentarily stopped, just give it a minute.
If you are asked whether you would like to restart R prior to installing, click on Yes. (If it immediately asks again, press No.)
If a message pops up saying you can ignore warning messages, click on OK.
Once all packages have been installed, restart R again.
Install Tex
Then run the following line by copy-pasting into the console and Enter:
::install_tinytex() tinytex
If you are asked whether you would like to restart R prior to installing, click on Yes. (If it immediately asks again, press No).
What’s going on here? We’ve installed the package called tinytex , but we also needed to run its function install_tinytex() to install Tex on your computer. So the tinytex package helps us install Tex, which is required in order to produce PDF outputs.
Note: Don’t worry if you have difficulties with the tinytex line or are getting error messages, this is common. You will still be able to produce outputs in the other formats and can have a go at troubleshooting later. Click here for a link to some troubleshooting suggestions.
Once this has run, you might see a message to reopen the R session and check if tinytex::is_tinytex() is TRUE. Run this bit of code in the Console to check and hopefully it will return TRUE.
::is_tinytex() tinytex
Note: Notice the triple colon, this is because it’s an internal variable name.
Hooray! You have installed all the relevant packages.
Download R Markdown Document into an RStudio Project
First, create a new project in RStudio, e.g., you can call it rmd_practice.
Then download the R Markdown file by right clicking on the link below and choosing, Save Link As, navigate to your newly created project folder, and save as working_document.Rmd
You can also right-click the button and choose “Save Link As…” to download.
⬇ Download working_document.Rmd
In RStudio, navigate to your newly created project folder and click to open your newly saved R Markdown document, working_document.Rmd (you can use the … in the Files tab to browse for your folder).
Open it and you are ready to go!
Knitting to 3 Different Formats We can Knit working_document.Rmd into HTML, PDF, and Word documents, either using Control+Shift+K to Knit the whole Rmd (RMarkdown) document, or the Knit button which has the following options:
You can set the output format of working_document.Rmd back to an html document by either:
- Pressing on the small arrow next to the Knit button and selecting “Knit to HTML” again (this moves html_document to the top of output:)
or
- Editing the YAML header and moving html_document to the top: