John Smith
John Smith

Reputation: 2886

RMarkdown Parameterise a Report

I have a report in R which generates charts and has some text. The text contains a reference to the previous week which is is itself based on a dataframe

I cant get it to run. Below is the code. Does anyone see the problem

I get the following error message

Error in yaml::yaml.load(enc2utf8(string), ...) : Scanner error: mapping values are not allowed in this context at line 5, column 9 Calls: ... yaml_load_utf8 -> mark_utf8 -> -> .Call Execution halted

---
title: "Foo"
author: "John Smith"
date: "18 October 2016"
output: word_document
  params:
  weeknr: !r max(data$WEEKNRs)
---

```{r}

# creates the dataframe referenced in the header
source('transform.R')

```

All,

Please find below [attached](www.stackexchange.com) report for week ``r params$weeknr``

Upvotes: 1

Views: 203

Answers (1)

Johannes Ranke
Johannes Ranke

Reputation: 469

The error you get is because you indented params: on the line after word_document.

It is possible to have code in the header, but you need to format it differently, see YAML current date in rmarkdown

In your case you can use something like (used the title tag in order to be able to easily see the result):

---
title:  "`r source('transform.R'); max(data$WEEKNRs)`"
---

Upvotes: 1

Related Questions