【发布时间】:2014-11-06 22:27:30
【问题描述】:
我正在使用knitr、R markdown 和自定义LaTeX 文件来编写手稿。摘要设置为 YAML frontmatter 的一部分。这很好用,除了我想包含在摘要中的结果是在文档的后面生成的。
在 YAML 中包含摘要对我来说很有意义,我更愿意以这种方式保留它。关于让摘要利用文档后面发生的计算的方法有什么想法吗?
一个简单的例子:
---
title: 'How do I interpret R objects in YAML that are created in the document?'
author: Jeff Hollister
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
html_document: null
word_document: null
fontsize: 11pt
documentclass: article
abstract: This is a test. Is this `r mean(x)` working?
---
This is a test of outputing a pdf, with R code interpretted in the YAML front mater. Use case
for this would be a manuscript, with abstract as part of YAML, and some of the results in the
abstract being calculated in the body of the Rmd. For instance:
```{r}
x<-rnorm(100)
mn<-mean(x)
mn
```
【问题讨论】:
-
也许是this helps?
-
我已经看到了,我可以解释 R,但不能利用作为文档正文的一部分创建的 R 对象。所以像:“抽象:这工作:
r mean(rnorm(100))”工作正常。 -
我明白了。如何使用代码外部化,即带有块的外部 R 文件,首先获取它,然后在文档中再次调用块。或者,使用 brew 进行预处理始终是一种选择。
-
考虑到我使用的乳胶文件,我认为这些可能是最好的选择。我现在倾向于将摘要从 yaml 中提取出来。我认为这会带来一些问题。
标签: r knitr r-markdown