change name of rmarkdown pdf and title from a parameter in render call

r, r-markdown

Solution

Question 1 is nicely answered here, you can use `params` to inject a new title into the YAML config:

---
output: html_document
params: 
    new_title: "My Title!"
title: "`r params$new_title`"
---

Then the output filenames for rendered files can be set by the `output_file` parameter of `rmarkdown::render`.

Problem

Here is some R markdown code in a "test_param.Rmd" file: ```` --- output: pdf_document params: number: "1" title: `r params$number` --- ```{r setup, include=TRUE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r one, include = TRUE} i = 2 #data = data.frame(x = c(1,2,3)) #for(i in 1:dim(data)[1]){ # plot(i*1000) #} ``` `r params$number` ```` that is called using a .r file here: ``` library(rmarkdown) rmarkdown::render("C://Users//me//Desktop//test_param.Rmd", params = list(number= "1")) ``` I get this error when I run the .r ``` Error in yaml::yaml.load(enc2utf8(string), ...) : Scanner error: while scanning for the next token at line 4, column 8found character that cannot start any token at line 4, column 8 ``` Any idea why? I am using `` not '' to do the title: `r params$number`

Original source

Related problems