Last active
August 9, 2021 02:37
-
-
Save cmguiob/248775841d43ce40937e9080877669b8 to your computer and use it in GitHub Desktop.
My workflow for rendering and saving automated reports.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Title" | |
subtitle: "Subtitle" | |
author: "Carlos Guio" | |
date: "`r Sys.Date()`" | |
knit: (function(inputFile, encoding) { | |
out_dir <- 'Subfolder_for_report'; | |
rmarkdown::render(input = inputFile, | |
encoding = encoding, | |
output_file = file.path( | |
here::here(), | |
out_dir, | |
'Report_name.html')) | |
}) | |
output: | |
html_document: | |
theme: journal | |
highlight: tango | |
keep_md: true | |
--- | |
I modified the YAML above to render the outputs in a different directory than the `.Rmd`. The `.Rmd`will be stored in the `/R`folder, whereas the `.html`and `.md`will be stored in the `/Reports` folder. | |
The folders need to be previously created following the structure: | |
* Project folder/ | |
+ R | |
+ Reports | |
+ Plots | |
+ Data | |
Next, use `r here::set_here()` just one time, to tag the root directory with a .here file | |
Set chunk options, including graphic display. | |
```{r setup_chunks, warning = FALSE, message = FALSE} | |
knitr::opts_chunk$set(include = FALSE, echo = FALSE, warning = FALSE, message = FALSE, fig.align="center", fig.showtext = TRUE, fig.retina = 1, dpi = 300, out.width = "70%") | |
showtext_auto() | |
#Following the advice from here: https://cran.rstudio.com/web/packages/showtext/vignettes/introduction.html | |
``` | |
To save the figures | |
```{r} | |
ggsave(file = "Figure_name.png", plot = object_in_R, device = "png", type = "cairo", path = here::here("Plots"), dpi = 300) | |
``` | |
After having created de `.Rmd`, run in the console `r knitr::purl("File_name.Rmd", documentation = 0)`. This will create an .R file, simplefied, without turning the Markdown text to comments. To add comments, set documentation = 2. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment