使用R markdown和knitr:可以在YAML中解释R对象

使用R markdown和knitr:可以在YAML中解释R对象,r,knitr,r-markdown,R,Knitr,R Markdown,我正在使用knitr,R markdown,以及一个定制的LaTeX文件来撰写手稿。摘要被设置为YAML frontmatter的一部分。这非常有效,只是我想在摘要中包含的结果将在文档的后面生成 在YAML中包含摘要对我来说是有意义的,我更愿意保持这种方式。关于如何让摘要利用文档后面的计算,有什么想法吗 一个简单的例子: --- title: 'How do I interpret R objects in YAML that are created in the document?' auth

我正在使用
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
```
---
标题:“如何解释YAML中在文档中创建的R对象?”
作者:杰夫·霍利斯特
输出:
pdf\U文件:
图片说明:是的
泰克斯:是的
部分数量:是
html_文档:空
word\u文档:空
字体大小:11磅
文档类:文章
摘要:这是一个测试。这是‘r’的意思(x)‘工作’吗?
---
这是一个输出pdf的测试,R代码在YAML前端进行解释。用例
因为这将是一份手稿,其中摘要是YAML的一部分,部分结果在
在Rmd正文中计算的摘要。例如:
```{r}

x它与YAML不完全相关,仅限于乳胶,但可能有帮助。抱歉,该线程是德语的,但可能代码不够清晰

您可以在创建报告时为摘要选择项目;这些项目被写入一个临时文件,类似于bibtex和biblatex中使用的方法,并在第二步合并到开始和结束(见附录)

作为一个软件包,您可以从下载。

Requirements 安装R、knitr和yaml:

sudo su -
apt-get install pandoc
apt-get install r
r
url <- "http://cran.us.r-project.org"
install.packages('knitr', repos=url)
install.packages('yaml', repos=url)
创建脚本 创建脚本以加载knitr、yaml和变量(例如,
knitr.sh
),当以标记格式提供文件时:

#/bin/bash
R-e\

“library(knitr);library(yaml);v maybe?我已经看到了这一点,我可以解释R,但是不能使用作为文档主体的一部分创建的R对象。因此类似这样的内容:“抽象:这是有效的:
R意味着(rnorm(100))
“很好,我明白了。如何使用代码外部化,即外部R文件与您的块,源代码,然后在文档中再次调用块。或者,使用brew进行预处理始终是一种选择。鉴于我使用的latex文件,我认为这些可能是最好的选择。我现在倾向于将摘要从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?
# `r v$title`
Author: `r v$author`
# How do I interpret R objects in YAML that are created in the document?
Jeff Hollister