【发布时间】:2019-12-03 22:05:44
【问题描述】:
我在 R Markdown 的 YAML 标头中声明了我的参数 Report_Date。我想使用 Report_Date 参数作为 header-includes 后面的行中的强制标头。无论我使用哪个字符,我似乎都无法引用该参数。
我尝试了我能想到的任何变体,并遵循了我发现的所有其他 SO。即使有些人的问题几乎相同,但答案对我不起作用,或者我做错了其他事情。
- \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 current date in rmarkdown
这是我当前的 YAML R Markdown 代码(它不在单独的模板文件中,只是在我想要创建的常规 .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
---
我最好有一个评估 paste0("Report Created for: ", params$Report_Date) 的左页眉和一个评估 paste0("Report Created on: ", format(Sys.time(), "%d %B, %Y")) 的页脚。
但现在我只接受一个包含Report_Date 参数的标题。
错误信息包括:
! Missing $ inserted.
<inserted text>
You may need to add $ $ around a certain inline R expression `r `
【问题讨论】:
-
你试过`r params$Report_Date`吗?
-
是的,我有,它有同样的错误
标签: r latex yaml r-markdown knitr