user3022875 user3022875 - 1 month ago 34
R Question

rmarkdown render not recognizing parameters

In my R file I have:

library(rmarkdown)

rmarkdown::render("C://Users//me//Desktop//test_param.Rmd",
params = list(region = "west"))


and in the rmd file:

---
title: "test"
output: pdf_document
params:
name: "test"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

`r params$name`


that rmd works when I run in separately.

BUT when I run the .r file I get this error

Error in knit_params_get(input_lines, params) :
render params not declared in YAML: region


what's the reason for this error?

Answer

knitr's override overrides existing params. You need to have a front matter like:

---
title: "test"
output: pdf_document
params:
  name: "test"
  region: ""
---