使用 knitcitations 在 RMarkdown 文档中包含参考书目 [英] Including Bibliography in RMarkdown document with use of the knitcitations

查看:18
本文介绍了使用 knitcitations 在 RMarkdown 文档中包含参考书目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 knitcitations 并将参考书目添加到我在 R Studio 中起草的 R Markdown 文档中.我的文档的标题如下所示:

---标题:一些标题"作者:《我》日期:2015 年 9 月"参考书目:参考书目.bib输出:pdf_文档:亮点:探戈number_sections: 是目录:是的---

我想使用以下代码在末尾添加参考书目:

```{r generateBibliography, echo=FALSE, eval=TRUE, message=FALSE, warning=FALSE}要求(针织引用")清洁围兜()选项(引文格式"=pandoc")read.bibtex(file = "bibliography.bib")```

参考文件bibliography.bib有以下内容:

@article{debarsy_testing_2010,title = {在固定效应面板数据模型中测试空间自相关},音量 = {40},issn = {0166-0462},网址 = {http://www.sciencedirect.com/science/article/pii/S0166046210000451},doi = {10.1016/j.regsciurbeco.2010.06.001},摘要 = {本文的目的是评估固定效应面板数据模型中空间自相关的相关性,并且肯定的是,确定最合适的空间规范,因为从交互异质性的建模角度来看,这似乎是一个关键点.因此,提出了几个 {LM} 测试统计量以及它们的 {LR} 对应物,它们允许区分内生空间滞后与空间自相关误差.蒙特卡罗实验显示了它们良好的有限样本性能.最后,在著名的 Feldstein-Horioka 谜题的框架中提供了一个经验应用.},页数 = {453--470},数字 = {6},journaltitle = {区域科学与城市经济学},shortjournal = {区域科学和城市经济学},作者 = {Debarsy, Nicolas and Ertur, Cem},网址日期 = {2015-10-01},日期 = {2010-11},关键字 = {面板数据、空间自相关、检验统计量}、文件 = {complex_zotero_path}}@article{lamichhane_spatial-temporal_2015,标题 = {邻里社会人口学特征和食品商店的时空建模},音量 = {181},issn = {0002-9262, 1476-6256},网址 = {http://aje.oxfordjournals.org/content/181/2/137},doi = {10.1093/aje/kwu250},摘要 = {关于食品商店、社区贫困和种族/民族的文献混杂在一起,缺乏解释食品资源复杂时空聚集的方法.我们使用了来自 Nielsen {TDLinx}(Nielsen Holdings NV,纽约,纽约)跨越 7 年(2006-2012)的超市和便利店位置的季度数据和来自美国社区调查(2006-2006-2010 年)评估 4 个{美国}城市(阿拉巴马州伯明翰;伊利诺伊州芝加哥;明尼苏达州明尼阿波利斯;加利福尼亚州旧金山)的大都会统计区 ({MSAs}) 中社区社会人口特征与食品店分布之间的关联.我们拟合了一个时空泊松回归模型,该模型通过在贝叶斯框架内的内在条件自回归模型中引入时空随机效应来解释商店位置的复杂时空相关结构.在考虑了人口普查区域层面的面积、人口、它们的相互作用以及空间和时间变异性之后,人口普查区域的贫困与所有 4 个 {MSA} 区域中预期超市数量的增加呈显着正相关.在伯明翰、明尼阿波利斯和旧金山的便利店也观察到了类似的正相关;在芝加哥,仅观察到以白色为主和以黑色为主的区域呈正相关.我们的研究结果表明,更多的食品店与更高的社区贫困率之间存在正相关关系,这对与社区贫困人口进入食品店相关的政策方法具有影响.},页数 = {137--150},数字 = {2},journaltitle = {美国流行病学杂志},短刊= {上午.J. Epidemiol.},作者 = {Lamichhane, Archana P. and Warren, Joshua L. and Peterson, Marc and Rummo, Pasquale and Gordon-Larsen, Penny},网址日期 = {2015-10-01},日期 = {2015-01-15},langid = {英文},pmid = {25515169},关键词 = {食品供应、食品商店、内在条件自回归模型、邻里特征、贫困、社会人口因素、时空模型、超市}、文件 = {complex_zotero_path}}

但是,生成的输出显示为注释,而不是书目条目:

文件是用以下代码编译的:

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS _paper.md --to latex--from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures--output _paper.pdf --filter pandoc-citeproc --table-of-contents --toc-depth 2 --template "path_latexdefault.tex"--number-sections --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in" --bibliography bibliography.bib

为简洁起见,我将路径更改为 _paper_paper.

<小时>

当我尝试遵循 关于在 RStudio 中包含参考书目的建议时,生成的文档没有书目条目.因此我的问题是,我在哪里犯了错误,在 RStudio 中工作时如何强制生成书目条目?

编辑

遵循非常有用的评论,理想情况下,我希望避免在附件中明确指出引用的作品.事实上,我有兴趣将参考书目包括在内,其中将包含一些被引用的作品,以及与主要文档相关但未在文档中明确引用的论文.

解决方案

pandoc 文档 说:

<块引用>

如果您想在参考书目中包含项目而不在正文中实际引用它们,您可以定义一个虚拟 nocite 元数据字段并将引用放在那里:

---无名:|@项目1,@项目2...@项目3

<块引用>

在此示例中,文档将仅包含 item3 的引文,但参考书目将包含 item1、item2 和 item3 的条目.

上面的整个代码块(从 ---...)可以放在代码中的任何位置.@abichat 更喜欢将它放在 YAML 之后或参考部分中.

I'm trying to use knitcitations and add bibliography to the R Markdown document that I'm drafting in R Studio. The header of my document looks like this:

---
title: "Some Title"
author: "Me"
date: "September 2015"
bibliography: bibliography.bib
output:
  pdf_document: 
    highlight: tango
    number_sections: yes
    toc: yes
---

I want to add the bibliography at the end using the following code:

```{r generateBibliography, echo=FALSE, eval=TRUE, message=FALSE, warning=FALSE}
require("knitcitations")
cleanbib()
options("citation_format" = "pandoc")
read.bibtex(file = "bibliography.bib")
```

The reference file bibliography.bib has the following content:

@article{debarsy_testing_2010,
    title = {Testing for spatial autocorrelation in a fixed effects panel data model},
    volume = {40},
    issn = {0166-0462},
    url = {http://www.sciencedirect.com/science/article/pii/S0166046210000451},
    doi = {10.1016/j.regsciurbeco.2010.06.001},
    abstract = {The aim of this paper is to assess the relevance of spatial autocorrelation in a fixed effects panel data model and in the affirmative, to identify the most appropriate spatial specification as this appears to be a crucial point from the modeling perspective of interactive heterogeneity. Several {LM} test statistics as well as their {LR} counterparts, which allow discriminating between endogenous spatial lag versus spatially autocorrelated errors, are therefore proposed. Monte Carlo experiments show their good finite sample performance. Finally, an empirical application is provided in the framework of the well-known Feldstein–Horioka puzzle.},
    pages = {453--470},
    number = {6},
    journaltitle = {Regional Science and Urban Economics},
    shortjournal = {Regional Science and Urban Economics},
    author = {Debarsy, Nicolas and Ertur, Cem},
    urldate = {2015-10-01},
    date = {2010-11},
    keywords = {Panel data, Spatial autocorrelation, Test statistics},
    file = {complex_zotero_path}
}

@article{lamichhane_spatial-temporal_2015,
    title = {Spatial-Temporal Modeling of Neighborhood Sociodemographic Characteristics and Food Stores},
    volume = {181},
    issn = {0002-9262, 1476-6256},
    url = {http://aje.oxfordjournals.org/content/181/2/137},
    doi = {10.1093/aje/kwu250},
    abstract = {The literature on food stores, neighborhood poverty, and race/ethnicity is mixed and lacks methods of accounting for complex spatial and temporal clustering of food resources. We used quarterly data on supermarket and convenience store locations from Nielsen {TDLinx} (Nielsen Holdings N.V., New York, New York) spanning 7 years (2006–2012) and census tract-based neighborhood sociodemographic data from the American Community Survey (2006–2010) to assess associations between neighborhood sociodemographic characteristics and food store distributions in the Metropolitan Statistical Areas ({MSAs}) of 4 {US} cities (Birmingham, Alabama; Chicago, Illinois; Minneapolis, Minnesota; and San Francisco, California). We fitted a space-time Poisson regression model that accounted for the complex spatial-temporal correlation structure of store locations by introducing space-time random effects in an intrinsic conditionally autoregressive model within a Bayesian framework. After accounting for census tract–level area, population, their interaction, and spatial and temporal variability, census tract poverty was significantly and positively associated with increasing expected numbers of supermarkets among tracts in all 4 {MSAs}. A similar positive association was observed for convenience stores in Birmingham, Minneapolis, and San Francisco; in Chicago, a positive association was observed only for predominantly white and predominantly black tracts. Our findings suggest a positive association between greater numbers of food stores and higher neighborhood poverty, with implications for policy approaches related to food store access by neighborhood poverty.},
    pages = {137--150},
    number = {2},
    journaltitle = {American Journal of Epidemiology},
    shortjournal = {Am. J. Epidemiol.},
    author = {Lamichhane, Archana P. and Warren, Joshua L. and Peterson, Marc and Rummo, Pasquale and Gordon-Larsen, Penny},
    urldate = {2015-10-01},
    date = {2015-01-15},
    langid = {english},
    pmid = {25515169},
    keywords = {food availability, food stores, intrinsic conditionally autoregressive model, neighborhood characteristics, Poverty, sociodemographic factors, spatial-temporal modeling, supermarkets},
    file = {complex_zotero_path}
}

However, the produced output appears as comments, not as bibliographic entry:

The file is compiled with this code:

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS _paper.md --to latex 
--from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures 
--output _paper.pdf --filter pandoc-citeproc --table-of-contents --toc-depth 2 --template "path_latexdefault.tex" 
--number-sections --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in" --bibliography bibliography.bib 

For brevity, I changed the paths to _paper and _paper.


When I tried to follow the advice on including bibliography in RStudio the document was produced with no bibliographic entries at all. Hence my question, where I'm making the mistake and how can I force generation of bibliographic entries when working in RStudio?

Edit

Following very useful comments, ideally I would like to avoid explicitly indicating cited works in the attached document. As a matter of fact, I'm interested in including bibliography that will consist of some cited works but also papers that are relevant to the main document but are not explicitly referenced in the document.

解决方案

The pandoc documentation says:

If you want to include items in the bibliography without actually citing them in the body text, you can define a dummy nocite metadata field and put the citations there:

---
nocite: |
  @item1, @item2
...

@item3

In this example, the document will contain a citation for item3 only, but the bibliography will contain entries for item1, item2, and item3.

The entire chunk above (from --- to ...) can go anywhere in your code. @abichat prefers to put it after the YAML or in the Reference section.

这篇关于使用 knitcitations 在 RMarkdown 文档中包含参考书目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆