ggll ggll - 2 months ago 26
R Question

Using rmarkdown::render to set document header (title, author, date)

I am using

rmarkdown::render("script.r")
to create an HTML version of an R script. The output starts with script.r as title, my login as author, and the current
date
as date. I don't want to give away my login, nor my work schedule..

I know this metadata (title, author, date) can be set in a YAML block inside a
Rmd
file, but I would like to avoid creating/editing this file, and work only with the original R script.

Is there a way to set (title, author, date) metadata via
rmarkdown::render
, or other functions like
knitr::opts_chunk$set
?

Alternatively, can this metadata be set inside the R script?

Please avoid suggesting that I should write an
Rmd
file instead..

Answer

The Rmarkdown documentation (see ?compile_notebook) describes one way to do this by including a specially formatted comment in your script.R file.

For example, include this comment in your script to set the title, author and date.

#' ---
#' title: "Crop Analysis Q3 2013"
#' author: "John Smith"
#' date: "May 3rd, 2014"
#' ---

This will give you the following output:

rmarkdown_output