cboettig / knitcitations

:package: Generate citations for knitr markdown and html files
http://carlboettiger.info
Other
219 stars 28 forks source link

Function to create bibkeys for entries that don't have them (such as dois) #6

Closed cboettig closed 12 years ago

cboettig commented 12 years ago

Done. All items, whether DOI or bibentry, get a bibkey generated automatically. A manual can be specified as the name to the object being passed in.

citep(c("10.1111/j.1461-0248.2005.00827.x", "10.1890/11-0011.1"))

[1] "(Halpern et. al. 2006; Abrams et. al. 2012)"

Which can take a list of DOIs to cite parenthetically. The citet and citep functions are automatically retrieving the available metadata via the Crossref API, and R is storing the information to generate the final bibliography.

Using and creating citation keys

When specifying a DOI for a citation, we can also give the citation a simple key name so we can use it later without having to remember the DOI, for instance, we can make the first citation of a particular example as

citep(c(Michaels = "10.1111/j.1755-263X.2012.00241.x"))

[1] "(Michaels & Tyre, 2012)"

and then later use

citep("Michaels")

[1] "(Michaels & Tyre, 2012)"

If we do not pass a key for the DOI we create, knitcitations will automatically generate a key of it's own using the last name of the first author and the year. For instance, based on one of the DOI-citations we have already created, we can do

citet("Halpern2006")

[1] "Halpern et. al. (2006)"

and knitcitations recognizes the key. The function will try to avoid collisions in the key: if it is given or creates a key matching one that is already in use, it will see if the titles of the articles match. If the are the same, the same key is used to avoid a duplicate entry. This makes it safe to call

citet(c(Halpern2006 = "10.1111/j.1461-0248.2005.00827.x"))

[1] "Halpern et. al. (2006)"

even if we have earlier or later cited by the doi alone. Collsion checking also avoids duplicating keys that correspond to different papers. If the titles are unique, knitcitations appends an underscore at the end of the automatically generated key. For instance, here we call a DOI that corresponds to a different citation with the same first author and year:

citet("10.1111/j.1523-1739.2005.00258.x")
Warning message: Automatic key generation found a copy of this key, using Halpern2006_ instead

[1] "Halpern et. al. (2006)"

A warning (not printed by knitr when this is used inline, but included in the log file) alerts us to the fact that this citation has been given an alternate key,

citet("Halpern2006_")

[1] "Halpern et. al. (2006)"

Of course if managing different keys sounds annoying, we can just call the DOI directly each time.