2015-10-05 72 views
12

我試圖使用knitcitations並將書目添加到我在R Studio中起草的R Markdown文檔中。我的文檔的標題是這樣的:在使用編織的RMarkdown文檔中包含參考書目

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

我想用下面的代碼在結尾處加上參考書目:

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

參考文件bibliography.bib有以下內容:

@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} 
} 

但是,生成的輸出顯示爲註釋,而不是書目條目: sample entries

該文件編譯使用此代碼:

"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_\latex\default.tex" 
--number-sections --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in" --bibliography bibliography.bib 

爲了簡便起見,我改變了路徑_paper_paper


當我試圖按照advice on including bibliography in RStudio沒有書目條目製作的所有文件。因此,我的問題,我犯了錯誤,在RStudio中工作時如何強制生成書目條目?

編輯

繼非常有用的意見,我非常希望避免明確說明所附文件中引用的作品。事實上,我有興趣將包括一些引用作品的書目,但也包括與主要文檔相關但未在文檔中明確引用的論文。

+1

也許你需要提供'csl'文件嗎? – zx8754

+1

@ zx8754我的理解是'csl'文件僅在特定樣式要求的情況下提供。目前,我只想附上相關出版物的清單。只要它能幫助讀者找到相關的工作,我就可以接受任何參考方式。 – Konrad

+0

是的,你是對的'csl'是格式風格,對不起,我仍然在我的嬰兒可重複研究世界的步驟。 – zx8754

回答

11

pandoc documentation說:

如果你想在書目項目,而不在正文實際上引用它們,你可以定義一個虛擬nocite元數據字段,並把引文有:

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

@item3 

在這個例子中,所述文件僅包含item3的引用,但參考書目將包含item1,item2和item3的條目。

+0

這是我想要做的,但是這個「nocite:|」在哪裏?走?我把它放在我的書目文件中,但這不起作用,而且它在我的降價文檔中似乎也不起作用。頂部的3個破折號是必要的嗎?而且,還有什麼需要關閉nocite部分,就像另一個垂直條? 我看到這是從RStudio文檔頁面複製的,但是我找不到任何其他信息來回答我的問題。 – svannoy

11

這裏是最小的工作示例:

paper.Rmd

--- 
title: 'My Title' 
author: "Me me me me!" 
output: pdf_document 
bibliography: references.bib 
--- 

Application written in the R programming language [@RCoreTeam] using the Shiny framework [@Chang2015]. 

# REFERENCES 

references.bib

@Misc{Chang2015, 
    Title     = {shiny: Web Application Framework for R. R package version 0.12.1}, 

    Author     = {Chang, W. and Cheng, J. and Allaire, JJ. and Xie, Y. and McPherson, J. }, 
    Year      = {2015}, 

    Type      = {Computer Program}, 
    Url      = {http://CRAN.R-project.org/package=shiny} 
} 


@Article{RCoreTeam, 
    Title     = {R: A Language and Environment for Statistical Computing}, 
    Author     = {{R Core Team}}, 
    Year      = {2015}, 

    Type      = {Journal Article}, 
    Url      = {http://www.R-project.org} 
} 

控制檯輸出

processing file: paper.Rmd 
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS paper.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output paper.pdf --filter pandoc-citeproc --template "C:\Users\tdadaev\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in" --bibliography references.bib 
output file: paper.knit.md 


Output created: paper.pdf 

紙。PDF enter image description here

+0

非常感謝您對我的文章感興趣並提供意見。實際上是否需要在文檔中使用Shiny框架[@Can2015] .'包含'[@RCoreTeam]?事實上,我只想附加參考書目而不是參考書目清單。有些文章與內容有關,但並未直接在文中提及。如果這是唯一的方法,我總是可以重新修改這個句子,並且包括正文中的引文,但是隻要附上相關作品的列表,我會更加快樂。 – Konrad

+1

@Konrad現在我看到你的問題,有趣的是,值得在你的文章中添加這一點。 – zx8754

+2

@Konrad我認爲它必須在文中提到,'.bib'文件的思想可以有數百個參考文獻,但只有'.rmd'文件中提到的文件被編譯爲pdf輸出中的參考。 – zx8754