ju.
ju.

Reputation: 1096

R read_yaml() reads a vector as parameter

I would like to read a .yaml file to get yaml parameters for a Rmarkdown report. Original I have a yaml header to define a vector.

---
params:
  ids: !r c(2455, 2490) 
---

and it works, where params$ids is a vector.

However, if I put ids: !r c(2455, 2490) into a report_params.yaml file, and read that yaml file by

report_params <- yaml::read_yaml("report_params.yaml")

now report_params$ids is a string 'c(2455, 2490)'. so what did I miss, and how should I fix this?

Upvotes: 3

Views: 1283

Answers (1)

Paul
Paul

Reputation: 9107

The YAML default handler uses !expr rather than !r.

report_params.yaml:

---
params:
  ids: !expr c(2455, 2490)
---
yaml::read_yaml("report_params.yaml")
#> $params
#> $params$ids
#> [1] 2455 2490

Upvotes: 7

Related Questions