R 脚本不是 Rmd中 yaml 标头中的正确 R 内联代码是什么?

问题描述

我正在尝试按照 https://bookdown.org/yihui/rmarkdown-cookbook/spin.html 将 R 脚本呈现为 html。

我想使用 roxygen2 约定并编写 R 脚本,以便我可以在需要时将它们呈现为报告或在没有 RStudio 的情况下运行。

我想知道在这种情况下如何获取自动日期计算。

下面的代码将导致 Yaml 中的 Errr:

Scanner error: while parsing a quoted scalar at line 3,column 7 found unkNown escape character at line 3,column 9

不正确的代码包括一个 attemt,其中在 yaml 的第 3 行,我试图输入计算出的低一行的日期。

#' ---
#' title: "Onko project"
#' author: "Jacek Kotowski"
#' date: "$\date$"
{{date <- Sys.Date()}}
#' output: 
#'   html_document:
#'     code_folding: show
#'     toc: true
#'     toc_float: false
#'     number_sections: true
#'     highlight: pygments
#'     df_print: paged
#'     css: style.css
#' ---

解决方法

date: "`r Sys.Date()`"

是我在 YAML 中用于内联 R 自动日期的内容,它将在呈现时为您提供当前系统日期