如何自动为knitr文件中的R包创建BibTex引用? [英] How to automatically create BibTex citations for R packages in knitr file?
问题描述
我不确定这是R,LaTeX还是BibTex问题.
I am not sure whether this an R, LaTeX, or BibTex problem.
我正在尝试自动生成一个.bib文件,其中包含R软件包的引用,然后在末尾列出它们.我能够生成BibTex文件,但看不到BibTex文件有任何问题,但是在编译PDF时条目不会出现.
I am trying to automatically generate a .bib file containing citations for R packages and then list them at the end. I am able to generate the BibTex file and I don't see anything wrong with the BibTex file, but the entries don't appear when I compile the PDF.
我不确定R是否不能正确生成BibTex文件,某些LaTeX语法是否错误,是否需要预编译BibTex文件等.我注意到\bibliography{NOT A REAL FILENAME}
将在没有抱怨的情况下生成引用"部分,但我认为这不是问题.
I'm not sure if R is not producing a BibTex file correctly, if some LaTeX syntax is wrong, or if the BibTex file needs to be pre-compiled or whatever. I noticed that \bibliography{NOT A REAL FILENAME}
will produce a References section without complaining, but I don't think that is the problem.
最小工作示例:
\documentclass[10pt]{amsart}
\usepackage[margin=1in, headheight=20pt, footskip=20pt]{geometry}
\begin{document}
<<label='Create References'>>=
require(knitr) # Needed for write_bib()
# Load some packages to the session:
require(xtable)
require(ggplot2)
# Select packages to cite:
citPkgs <- names(sessionInfo()$otherPkgs)
# Write the bibtex file:
write_bib(citPkgs, file="R-Pckgs.bib")
@
\nocite{*}
\bibliographystyle{plain}
\bibliography{R-Pckgs.bib}
\end{document}
任何帮助或建议将不胜感激.
Any help or suggestions would be appreciated.
推荐答案
只需将\bibliography{R-Pckgs.bib}
替换为\bibliography{R-Pckgs}
,它就可以正常工作.
Just replace \bibliography{R-Pckgs.bib}
with \bibliography{R-Pckgs}
, and it should work fine.
在Windows 7上,使用最新的MikTeX安装和当前的R和R软件包,可以进行以下操作:
On Windows 7, with an up-to-date MikTeX installation and current R and R packages, the following worked:
- 将可复制的示例放在名为
"eg.Rnw"
的文件中,然后进行编辑以删除多余的".bib"
- 启动R并导航到
"eg.Rnw"
所在的目录. - 执行
library(knitr); knit2pdf("eg.Rnw")
- Put your reproducible example in a file named
"eg.Rnw"
and edit to remove the extraneous".bib"
- Launch R and navigate to the directory in which
"eg.Rnw"
is located. - Do
library(knitr); knit2pdf("eg.Rnw")
注意:从*.Rnw
到*.pdf
的工作流显然很多,但是,如果要(至少)要使用knit2pdf()
,请确保从包含要处理的*.Rnw
的目录.
Note: There are obviously many workflows for going from *.Rnw
to *.pdf
, but if you want to use knit2pdf()
(at least), make sure that you run it from the directory containing the *.Rnw
to be processed.
这篇关于如何自动为knitr文件中的R包创建BibTex引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!