如何在 knitr 文件中为 R 包自动创建 BibTex 引用? [英] How to automatically create BibTex citations for R packages in knitr file?

查看:29
本文介绍了如何在 knitr 文件中为 R 包自动创建 BibTex 引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是 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 文件或其他什么.我注意到 ibliography{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 ibliography{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}

egin{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")
@


ocite{*}
ibliographystyle{plain}
ibliography{R-Pckgs.bib}

end{document}

任何帮助或建议将不胜感激.

Any help or suggestions would be appreciated.

推荐答案

只需将 ibliography{R-Pckgs.bib} 替换为 ibliography{R-Pckgs},它应该可以正常工作.

Just replace ibliography{R-Pckgs.bib} with ibliography{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:

  1. 将可重现的示例放入名为 "eg.Rnw" 的文件中并进行编辑以删除无关的 ".bib"
  2. 启动 R 并导航到 "eg.Rnw" 所在的目录.
  3. library(knitr);knit2pdf("eg.Rnw")
  1. Put your reproducible example in a file named "eg.Rnw" and edit to remove the extraneous ".bib"
  2. Launch R and navigate to the directory in which "eg.Rnw" is located.
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆