You are working on a team that needs to provide regular updates about a dataset that is regularly updated. Currently, an employee does the following steps once per week:
This takes the employee about 3 hours every week. You are a new member of the team and you confidently declare you could automate the procedure using R and Quarto (and that you could complete the automation in less than three hours!). The team looks at you with wide eyes. You realize you better get working.
You can specify that Quarto should produce multiple outputs using the following syntax in the YAML header:
format:
html: default
gfm: default
pptx: default
docx: default
You can read more about the YAML header and all the options here. Note that you can specify many options for each output format to change the theme, structure, etc.
However, if you click the “Render” button in RStudio, it will only make one output. To ‘render’ all of them, you have to use a command like this in the R Console.
quarto::quarto_render("path/to/file.qmd",output_format = "all")
You will be working with the data available here. You
can read it in using read_table()
but you will have to look
at the text file and specify how many lines to skip
.
Your objective is to automatically produce various outputs like MS Word, PPTX, and HTML.
The document should:
File -> New File -> Quarto Document
)readr
::read_table()` or similar to import the
dataset into R directly from the URL (ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_annmean_mlo.txt)skip
parameter of read_table()
or
potentially use the comment character #
. You can also use
col_names
to name the columns correctly.knitr::kable()
or similar.quarto::render("path/to/file.qmd",output_format = "all")
to
render all the outputs specified in the YAML.results='hide',message=FALSE, echo=F
.as_image()
in kableExtra package which
generates a png file that is easy to embed. You can use it like
this:data %>%
kable() %>%
as_image(width = 10,file = "table.png")
You may want to play with the kable_styling()
function
to adjust the table’s appearance. 7. Save the outputs in your
repository.
Explore my version of the html output here.
Think about how you could use this “one document, several outputs” approach in a project.