rmarkdown-book icon indicating copy to clipboard operation
rmarkdown-book copied to clipboard

Improve examples for parametrized report

Open nettoyoussef opened this issue 5 years ago • 1 comments

This is not an issue, but a recommendation.

I would like to suggest that in the docs available in the Rmarkdown book you include two examples in chapter 15 (parameterized reports):

  • passing parameters as raw markdown text for the parameterized reports.
  • setting the title using a parameter

This information is available in other parts of the book, but I think including them there would make easier for other people starting to create report templates.

For example, something as such in the .Rmd file:

---
output: html_document
params:
  author: author
  date: !r lubridate::today()
  set_title: title
  obs: my_text_chunk_with_markdown
title: "`r params$set_title`"  
---

This is my parameter with markdown in a chunk:

 ```{r, results='asis', echo=FALSE}
 cat(params$obs)
 ```

This is my parameter with markdown with code inline: `r paste(params$obs)`.

and something as such for the script that renders it:

rmarkdown::render(
  path_to_file,
  params = list(
                 set_title =  'title',
                 author =  'author',
                 obs = 'This is a text with *markdown* syntax.',
       ),
  output_file = 'my_report.html')
)

nettoyoussef avatar Oct 11 '19 14:10 nettoyoussef

For reference, we have added an example about setting the title dynamically in https://bookdown.org/yihui/rmarkdown-cookbook/dynamic-yaml.html

I'll move the issue to the rmarkdown book

cderv avatar Jan 11 '22 11:01 cderv