如何将参考文献和参考书目插入使用 RStudio R Sweave 和 knitr 生成的 .Rnw 文件中?

如何将参考文献和参考书目插入使用 RStudio R Sweave 和 knitr 生成的 .Rnw 文件中?

到目前为止,我已经成功使用 RStudio 和 R Markdown 撰写科学论文并插入医学文献中的引文,没有出现重大问题,如下面的最小示例(MWE)所示,它生成了一个 .pdf 文件。

---
title: ""
csl: nature.csl
output: pdf_document
bibliography: BIBLIOGRAPHY_24th_March_2019.bib
---

Meningiomas which are thought to arise from arachnoidal cap cells, are the most common meningeal tumours [@louis_2016_2016].

# References

我现在开始写博士论文,一直用 RStudio,但这次用的是 R Sweave(编织 .Rnw 文件),因为我想使用 Latex 的功能。理论上看似简单,但实际上并非如此。

以下 MWE 产生此错误:

using fall-back bibtex(8) backend: functionality may be reduced/unavailable...
\documentclass{article}

\usepackage[backend= bibtex]{biblatex}
% or \usepackage[backend= biber]{biblatex}

\addbibresource{BIBLIOGRAPHY_24th_March_2019.bib}
% or %\bibliography{BIBLIOGRAPHY_24th_March_2019}

<<setup, eval= TRUE, include=FALSE, cache=FALSE, echo=FALSE>>=
Sys.setenv(TEXINPUTS=getwd(),
           BIBINPUTS=getwd(),
           BSTINPUTS=getwd())
@ 



\begin{document}

Meningiomas which are thought to arise from arachnoidal cap cells, are the most common meningeal tumours subtypes \cite{louis_2016_2016}.

\printbibliography   

\end{document}

我的简单书目文件( )与文件(BIBLIOGRAPHY_24th_March_2019.bib)存储在同一个文件夹中,构建方式如下:mwe.RnwC:\Users\Charles\Documents\R

@article{louis_2016_2016,
    title = {The 2016 World Health Organization Classification of Tumors of the Central Nervous System: a summary},
    volume = {131},
    issn = {1432-0533},
    doi = {10.1007/s00401-016-1545-1},
    shorttitle = {The 2016 World Health Organization Classification of Tumors of the Central Nervous System},
    pages = {803--820},
    number = {6},
    journaltitle = {Acta Neuropathologica},
    shortjournal = {Acta Neuropathol.},
    author = {Louis, David N. and Perry, Arie and Reifenberger, Guido and von Deimling, Andreas and Figarella-Branger, Dominique and Cavenee, Webster K. and Ohgaki, Hiroko and Wiestler, Otmar D. and Kleihues, Paul and Ellison, David W.},
    date = {2016-06},
    pmid = {27157931}
}

我浏览过无数网页(https://cimentadaj.github.io/phd_thesis/thesis_template_example/2017-10-24-thesis-template.htmlhttps://texblog.org/2013/08/20/rknitr-automatic-bibliography-generation-with-biblatex-in-rstudio/https://stackoverflow.com/questions/33332654/with-knitr-and-rnw-for-latex-how-do-you-print-the-full-bibliography-in-pdf-out等等),并尝试了不同的包,甚至在我的.Rnw文档中添加了以下代码块,但都没有成功:

    Sys.setenv(TEXINPUTS=getwd(),
               BIBINPUTS=getwd(),
               BSTINPUTS=getwd())

我的书目(BIBLIOGRAPHY_24th_March_2019.bib)文件是从 Zotero 导出的。

我使用 Windows 10、MikTeX for LaTeX。所有软件包和软件都是最新的。

我的问题是:有谁知道简单有效的方法将参考文献(甚至直接从带有 DOI 的网络)插入到.Rnw使用 Rstudio、R Sweave 和knitr?生成的文件中

答案1

按照 Fran 的建议,它的工作原理是在序言中(在 \begin{document} 之前)添加以下块代码并更改\usepackage{biblatex}\usepackage[backend=biber]{biblatex}

<<setup, eval= TRUE, include= FALSE, cache= FALSE, echo= FALSE>>=
system (paste ("biber", sub ("\\.Rnw$", "", current_input())))
@

我完全不知道它有什么用,但它解决了这个问题。请注意,您有编译(至少)两次每次更改文档名称时例如mwe_2.Rnw 到 mwe_3.Rnw。此外,不要cache = TRUE在 knitr 块中设置。

我的工作 MWE 如下:

\documentclass{article}

\usepackage[backend= biber]{biblatex}

\bibliography{BIBLIOGRAPHY_24th_March_2019}
% or \addbibresource{BIBLIOGRAPHY_24th_March_2019.bib}

<<biber, eval= TRUE, include= FALSE, cache= FALSE, echo= FALSE>>=
system (paste ("biber", sub ("\\.Rnw$", "", current_input())))
@               

\begin{document}

Meningiomas which are thought to arise from arachnoidal cap cells, are the most common meningeal tumours subtypes \cite{louis_2016_2016}.
Malignant meningioma is a highly aggressive and often fatal variant that ... \cite{jenkinson_radiotherapy_2014}.
The behaviour and outcome of WHO Grade II meningiomas also called atypical are intermediate as they show a ... \cite{champeaux_who_2016}.

\printbibliography   

\end{document}

该问题的答案已在这里讨论:knitr 和 biblatex

显然,这个问题也可以通过 latexmk 来解决https://mg.readthedocs.io/latexmk.html#,但它对我来说看起来太复杂了。

谢谢大家。

相关内容