R read_yaml() 读取一个向量作为参数 [英] R read_yaml() reads a vector as parameter

查看:42
本文介绍了R read_yaml() 读取一个向量作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取 .yaml 文件以获取 Rmarkdown 报告的 yaml 参数.原来我有一个 yaml 头来定义一个向量.

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) 
---

它可以工作,其中 params$ids 是一个向量.

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

但是,如果我将 ids: !r c(2455, 2490) 放入 report_params.yaml 文件中,并通过

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")

现在 report_params$ids 是一个字符串 'c(2455, 2490)'.那么我错过了什么,我应该如何解决这个问题?

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

推荐答案

YAML 默认处理程序使用 !expr 而不是 !r.

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

这篇关于R read_yaml() 读取一个向量作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆