Search code examples
ryamlr-markdownrstudioroxygen2

What is a correct R Inline code in yaml header in an R script (not Rmd)?


I am trying to follow https://bookdown.org/yihui/rmarkdown-cookbook/spin.html to render an R script to html.

I would like to use roxygen2 conventions and write R scripts so that I can render them to a report if needed or run without RStudio.

I am wondering how to acquire automatic date calculation in this case.

The code below will result in an Errr in Yaml:

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

The incorrect code includes an attemt where at line 3 of yaml I am trying to enter a date calculated a line lower.

#' ---
#' 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
#' ---

Solution

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

    is what I use for inline R auto date in the YAML, which will give you the current system date when rendering