Use R code or Windows user variable (“%userprofile%”) in YAML?

后端 未结 2 2012
不知归路
不知归路 2020-11-30 11:53

In my yaml call I have

---
title: \"`r paste0(\'Test. Done \', format(Sys.Date(), \'%B-%Y\'))`\"
output:
  word_document:
    fig_caption: yes
    fig_height         


        
2条回答
  •  野性不改
    2020-11-30 12:17

    You can include such a variable, but you should quote the scalar in which put it (either single quotes or double quotes). Within a quoted scalar the % doesn't have any special meaning only the single quote has (in single quoted strings, or the backslash (\) in double quoted strings.

    Any further interpretation of that scalar as Windows variable is outside of the scope of YAML and needs to be done by your program.

    The scalar:

    "`r file.path(path.expand('~'), 'skabelon.docx')`"
    

    is correct YAML and shout not throw an error (but of course is nothing else for YAML than a buch of characters starting and ending with a backquote, no interpretation should be done on that by the parser).

提交回复
热议问题