Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在带有参数的YAML割台刀中使用YAML set参数_R_Latex_Yaml_R Markdown_Knitr - Fatal编程技术网

R 在带有参数的YAML割台刀中使用YAML set参数

R 在带有参数的YAML割台刀中使用YAML set参数,r,latex,yaml,r-markdown,knitr,R,Latex,Yaml,R Markdown,Knitr,我在R Markdown中的YAML标题中声明我的参数报告\ U日期。我想将Report_Date参数用作header中的一个强制标题,该标题包含其后面的行。无论我使用哪个字符,我似乎都无法引用该参数 我尝试了我能想到的任何变化,并遵循所有其他,所以我找到了。尽管有些问题几乎相同,但答案对我来说并不适用,或者我做错了别的事情 - \fancyhead[LO,LE]{"'r params$Report_Date'"} - \fancyhead[LO,LE]{r params$Report_Date

我在R Markdown中的YAML标题中声明我的参数报告\ U日期。我想将Report_Date参数用作header中的一个强制标题,该标题包含其后面的行。无论我使用哪个字符,我似乎都无法引用该参数

我尝试了我能想到的任何变化,并遵循所有其他,所以我找到了。尽管有些问题几乎相同,但答案对我来说并不适用,或者我做错了别的事情

- \fancyhead[LO,LE]{"'r params$Report_Date'"}
- \fancyhead[LO,LE]{r params$Report_Date}
- \fancyhead[LO,LE]{\"'r params$Report_Date'"}
- \fancyhead[LO,LE]{\r params$Report_Date'}
- \fancyhead[LO,LE]{'`r params$Report_Date`'}
- \fancyhead[LO,LE]{'r params$Report_Date'}
- \fancyhead[LO,LE]{$"'r params$Report_Date'"$}
- \fancyhead[LO,LE]{$"'r params$Report_Date'"}
- \fancyhead[LO,LE]{\$r params$Report_Date'"$}
- \fancyhead[LO,LE]{$"'r params$Report_Date'"$}
- \fancyhead[LO,LE]{$'r params$Report_Date'$}
- \fancyhead[LO,LE]{"r params$Report_Date"}
甚至尝试过:

includes:

in_header:'`r params$Report_Date`'
如中所述:

这是我当前的YAML R标记代码,它不在单独的模板文件中,只在我要创建的常规.rmd文件中

 ---
    title: "Monthly Diagnostic Report"
    author: "Morgan :)"
    date: "July 12, 2019"
    toc: true
    params:
      Report_Date: "YYYY-MM-DD"
    header-includes:
    - \usepackage{fancyhdr}
    - \pagestyle{fancy}
    - \fancyhead[CO,CE]{Monthly Diagnostic Report}
    - \fancyhead[LO,LE]{"'r params$Report_Date'"}
    - \fancyfoot[RE,RO]{\thepage}
    output: pdf_document
    ---
我最好有一个左页眉,用于评估为以下内容创建的paste0Report:,参数$Report_Date,还有一个页脚,用于评估在以下内容创建的paste0Report:,formatSys.time,%d%B,%Y

但现在我只接受包含Report\u Date参数的标题

错误消息包括:

! Missing $ inserted.
<inserted text>
You may need to add $ $ around a certain inline R expression `r `

唯一对我有意义的语法是

---
output: pdf_document
params:
      Report_Date: "YYYY-MM-DD"
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[LO,LE]{`r params$Report_Date`}
---
如果使用该选项,则会收到另一条关于参数未知的错误消息。这是有意义的,因为只有在解析YAML头之后才定义参数。幸运的是,在LaTeX speak中的\begin{document}之后,还可以在文档正文中使用\fancyhead和\fancyfoot。因此,以下内容应为您提供所需的输出:

---
output: pdf_document
params:
      Report_Date: "YYYY-MM-DD"
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{Monthly Diagnostic Report}
- \fancyfoot[RE,RO]{\thepage}
---

\fancyhead[LO,LE]{Report created for: `r params$Report_Date`}
\fancyfoot[CO,CE]{Report created on: `r format(Sys.time(), '%d %B, %Y')`}

<actual content>

注意:我也在正文中设置创建日期,因为很难在YAML标题中输入文字冒号

您是否尝试过“r params$Report\u Date”?是的,它有相同的错误。如何格式化它?我将下面的两行代码添加到代码的最后一行,而不是一个区块中,它甚至没有在这两个额外的标题上显示任何内容,所以我将它添加到区块中,它不喜欢从第28-31行开始/退出每月\u诊断\u报告\u parsetext=x中的code.Rmd错误,srcfile=src::2:1:意外输入1:所有注释都在第6个块中,后面的块都是相同的2:^因此我在其中添加了一个-,现在我得到了一个解析代码错误…@morg这两行应该在实际内容之前。是的,这很有效!非常感谢!!我尝试了几天,没有其他论坛能如此轻松地给出这个答案: