2015-10-05 18 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 

、Iは_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つのダッシュは必要ですか?そして、別の垂直バーのように、ノーサイトセクションを閉じるために必要なものはありますか? これは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 framework [@ Chang2015]を使って '[@RCoreTeam]を含めることは実際には必要ですか?実際、参考文献のリストではなく、参考文献を添付したいだけです。内容に関連しているが、テキストに直接言及されていない論文もある。これが唯一の方法であれば、私はいつもその文を言い換えて本文中の引用を含めることができますが、関連する作品のリストを追加するだけでもっと幸せになれます。 – Konrad

+1

@Konrad今、私はあなたの問題を見て、面白い、あなたのポストにこの点を追加する価値がある。 – zx8754

+2

@Konrad私はそれがテキストで言及されなければならないと思う、アイデアは '.bib'ファイルが何百ものrefを持つことができるが、' .rmd'ファイルに言及されたものだけがpdf出力の参考文献としてコンパイルされる。 – zx8754