2015-10-05 13 views
12

Sto provando a utilizzare knitcitations e aggiungere bibliografia al documento R Markdown che sto elaborando in R Studio. L'intestazione del mio documento è simile al seguente:Includere bibliografia nel documento RMarkdown con l'uso delle knitcitations

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

voglio aggiungere la bibliografia alla fine utilizzando il seguente codice:

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

Il file di riferimento bibliography.bib ha il seguente contenuto:

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

Tuttavia, l'output prodotto viene visualizzato come commenti, non come voce bibliografica: sample entries

Il file viene compilato con questo codice:

"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 

Per brevità, ho cambiato i percorsi per _paper e _paper.


quando ho cercato di seguire il advice on including bibliography in RStudio il documento è stato realizzato senza voci bibliografiche a tutti. Quindi la mia domanda, , dove sto facendo l'errore e come posso forzare la generazione di voci bibliografiche quando si lavora in RStudio?

Modifica

In seguito alle osservazioni molto utili, idealmente vorrei evitare esplicitamente indicare opere citate nel documento allegato. In effetti, sono interessato ad includere la bibliografia che consisterà in alcune opere citate, ma anche in documenti che sono rilevanti per il documento principale ma che non sono esplicitamente citati nel documento.

+1

Forse è necessario fornire anche il file 'csl'? – zx8754

+1

@ zx8754 ho capito che il file 'csl' viene fornito solo in caso di requisiti di stile specifici. In questo momento, mi interessa solo allegare un elenco di pubblicazioni pertinenti. Posso vivere con qualsiasi stile di riferimento non appena aiuta i lettori a trovare il lavoro pertinente. – Konrad

+0

Sì, hai ragione 'csl' è per lo stile di formattazione, mi spiace, sono ancora sui miei piccoli passi nel mondo della ricerca riproducibile. – zx8754

risposta

11

Il pandoc documentation dice:

Se si desidera includere elementi nella bibliografia senza peraltro riuscire a citare nel corpo del testo, è possibile definire un campo di metadati nocite fittizio e mettere le citazioni lì:

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

@item3 

In questo esempio, la il documento conterrà una citazione solo per item3, ma la bibliografia conterrà voci per item1, item2 e item3.

+0

Questo è quello che voglio fare, ma da dove viene questo "nocite: |" partire? L'ho inserito nel mio file bibliografico ma non ha funzionato e non sembra funzionare nel mio documento markdown. I 3 trattini in cima sono necessari? E c'è qualcosa di necessario per chiudere la sezione nocite, come un'altra barra verticale? Vedo che questo è stato copiato dalla pagina di documentazione di RStudio, ma non sono riuscito a trovare alcuna informazione aggiuntiva lì per rispondere alla mia domanda. – svannoy

11

Ecco minimo esempio di funzionamento:

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

uscita Console

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 

carta.pdf enter image description here

+0

Grazie mille per aver mostrato l'interesse nel mio post e aver fornito i commenti. È effettivamente necessario includere '[@RCoreTeam] usando il framework Shiny [@ Chang2015] .' nel documento? In effetti, vorrei semplicemente allegare una bibliografia non una lista di riferimenti. Ci sono alcuni documenti che sono rilevanti per il contenuto ma non sono direttamente citati nel testo. Se questo è l'unico modo, posso sempre riformulare la frase e includere la citazione nel testo, ma sarei molto più felice con la lista appena aggiunta delle opere pertinenti. – Konrad

+1

@Konrad Ora vedo il tuo problema, interessante, vale la pena aggiungere questo punto al tuo post. – zx8754

+2

@Konrad Penso che debba essere menzionato nel testo, l'idea è che il file '.bib' può avere centinaia di refs, ma solo quelli menzionati nel file' .rmd' vengono compilati come riferimenti in output PDF. – zx8754

Problemi correlati