| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/citation.R |
| 3 |
\name{pkg_bib} |
| 4 |
\alias{pkg_bib} |
| 5 |
\title{Generate BibTeX bibliography databases for R packages} |
| 6 |
\usage{ |
| 7 |
pkg_bib( |
| 8 |
x = .packages(), |
| 9 |
file = "", |
| 10 |
tweak = TRUE, |
| 11 |
width = NULL, |
| 12 |
prefix = getOption("xfun.bib.prefix", "R-"), |
| 13 |
lib.loc = NULL, |
| 14 |
packageURL = TRUE, |
| 15 |
date = c("none", "package", "today") |
| 16 |
) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{x}{Package names. Packages which are not installed are ignored.} |
| 20 |
|
| 21 |
\item{file}{The (\file{.bib}) file to write. By default, or if \code{NULL}, output |
| 22 |
is written to the R console.} |
| 23 |
|
| 24 |
\item{tweak}{Whether to fix some known problems in the citations, especially |
| 25 |
non-standard format of author names.} |
| 26 |
|
| 27 |
\item{width}{Width of lines in bibliography entries. If \code{NULL}, lines will |
| 28 |
not be wrapped.} |
| 29 |
|
| 30 |
\item{prefix}{Prefix string for keys in BibTeX entries; by default, it is |
| 31 |
\verb{R-} unless \code{option('xfun.bib.prefix')} has been set to another string.} |
| 32 |
|
| 33 |
\item{lib.loc}{A vector of path names of R libraries.} |
| 34 |
|
| 35 |
\item{packageURL}{Use the \code{URL} field from the \file{DESCRIPTION} file. See |
| 36 |
Details below.} |
| 37 |
|
| 38 |
\item{date}{The way to include a date of the form \verb{(retrieved YYYY-mm-dd)} in |
| 39 |
the \code{note} field of bib entries. For \code{date = 'none'}, no date is included. |
| 40 |
For \code{date = 'package'}, the \code{\link[=packageDate]{packageDate()}} of the package is included. For |
| 41 |
\code{date = 'today'}, \code{\link[=Sys.Date]{Sys.Date()}} is included. Alternatively, you can provide |
| 42 |
a date directly, e.g., \verb{date = '2025-04-01'.}} |
| 43 |
} |
| 44 |
\value{ |
| 45 |
A list containing the citations. Citations are also written to the |
| 46 |
\code{file} as a side effect. |
| 47 |
} |
| 48 |
\description{ |
| 49 |
Call \code{\link[utils:citation]{utils::citation()}} and \code{\link[utils:toBibtex]{utils::toBibtex()}} to create bib entries for R |
| 50 |
packages and write them in a file. It can facilitate the auto-generation of |
| 51 |
bibliography databases for R packages, and it is easy to regenerate all the |
| 52 |
citations after updating R packages. |
| 53 |
} |
| 54 |
\details{ |
| 55 |
For a package, the keyword \code{R-pkgname} is used for its bib item, where |
| 56 |
\code{pkgname} is the name of the package. Citation entries specified in the |
| 57 |
\file{CITATION} file of the package are also included. The main purpose of |
| 58 |
this function is to automate the generation of the package citation |
| 59 |
information because it often changes (e.g., the author, year, package |
| 60 |
version, and so on). |
| 61 |
|
| 62 |
There are at least two different uses for the URL in a reference list. You |
| 63 |
might want to tell users where to go for more information. In that case, use |
| 64 |
the default \code{packageURL = TRUE}, and the first URL listed in the |
| 65 |
\file{DESCRIPTION} file will be used. Be careful: some authors don't put the |
| 66 |
most relevant URL first. Alternatively, you might want to identify exactly |
| 67 |
which version of the package was used in the document. If it was installed |
| 68 |
from CRAN or some other repositories, the version number identifies it, and |
| 69 |
\code{packageURL = FALSE} will use the repository URL (as used by |
| 70 |
\code{\link[utils:citation]{utils::citation()}}). |
| 71 |
} |
| 72 |
\note{ |
| 73 |
Some packages on CRAN do not have standard bib entries, which was once |
| 74 |
reported by Michael Friendly at |
| 75 |
\url{https://stat.ethz.ch/pipermail/r-devel/2010-November/058977.html}. I |
| 76 |
find this a pain, and there are no easy solutions except contacting package |
| 77 |
authors to modify their DESCRIPTION files. The argument \code{tweak} has |
| 78 |
provided hacks to deal with known packages with non-standard bib entries; |
| 79 |
\code{tweak = TRUE} is by no means intended to hide or modify the original |
| 80 |
citation information. It is just due to the loose requirements on package |
| 81 |
authors for the DESCRIPTION file. On one hand, I apologize if it really |
| 82 |
mangles the information about certain packages; on the other, I strongly |
| 83 |
recommend package authors to consider the \code{Authors@R} field (see the |
| 84 |
manual \emph{Writing R Extensions}) to make it easier for other people to cite R |
| 85 |
packages. |
| 86 |
} |
| 87 |
\examples{ |
| 88 |
pkg_bib(c("base", "MASS", "xfun")) |
| 89 |
pkg_bib("cluster", prefix = "R-pkg-") # a different prefix |
| 90 |
pkg_bib("xfun", date = "package") |
| 91 |
} |
| 92 |
\author{ |
| 93 |
Yihui Xie and Michael Friendly |
| 94 |
} |