From Ach|m@Ze||e|@ @end|ng |rom u|bk@@c@@t  Thu May 30 00:46:40 2019
From: Ach|m@Ze||e|@ @end|ng |rom u|bk@@c@@t (Achim Zeileis)
Date: Thu, 30 May 2019 00:46:40 +0200 (CEST)
Subject: [Rd] Making a package CITATION file from BibTeX
In-Reply-To: <D3161B69-D245-47A3-BBC0-030CA767EFC9@mrc-lmb.cam.ac.uk>
References: <D3161B69-D245-47A3-BBC0-030CA767EFC9@mrc-lmb.cam.ac.uk>
Message-ID: <alpine.DEB.2.21.1905300038070.6310@paninaro>

On Thu, 30 May 2019, Dr Gregory Jefferis wrote:

> Dear Colleagues,
>
> I would like to provide a CITATION file for my package nat.nblast [1].
>
> I have the correct citation in BibTeX format [2]. How can I convert this 
> BibTeX to the format needed by R for a package CITATION file (I have a 
> lot of other packages needing citations ...).

(1) You can use read.bib() from the "bibtex" package to read the .bib file 
containing the relevant reference.

(2) This gives you a "bibentry" object that can be turned into the R code 
generating it with format(..., style = "R") from the basic "utils" 
package.

(3) Then you can writeLines() this R code on the console or 
writeLines(..., "CITATION") to a CITATION file.

(4) Optionally you can also include a $header in your bibentry with a 
short introductory sentence. Or if you have multiple references to go into 
the same CITATION you might want to include a $header for each and an 
$mheader for everything.

A worked example is included below. Background information is given in: 
https://doi.org/10.32614/RJ-2012-009

Let's assume that your BibTeX entry [2] is the first entry in a file 
called "my.bib". Then you can do:

## read first item from BibTeX as "bibentry" object
b <- bibtex::read.bib("my.bib")[[1]]

## delete the bib key and add a header for the citation
b$key <- NULL
b$header <- "To cite nat.nblast in publications use:"

## turn the "bibentry" into the R code generating it
b <- format(b, style = "R")

## write the R code to the console
writeLines(b)

bibentry(bibtype = "Article",
          header = "To cite nat.nblast in publications use:",
          author = c(person(given = "Marta",
                            family = "Costa"),
                     person(given = c("James", "D"),
                            family = "Manton"),
                     person(given = c("Aaron", "D"),
                            family = "Ostrovsky"),
                     person(given = "Steffen",
                            family = "Prohaska"),
                     person(given = c("Gregory", "S", "X", "E"),
                            family = "Jefferis")),
          doi = "10.1016/j.neuron.2016.06.012",
          journal = "Neuron",
          month = "Jul",
          number = "2",
          pages = "293-311",
          title = "NBLAST: Rapid, Sensitive Comparison of Neuronal 
Structure and Construction of Neuron Family Databases",
          volume = "91",
          year = "2016")


> I think what I need is the opposite of RefManageR::toBiblatex [3]. This seems 
> like it should be a common need, so I feel sure I must be missing something, 
> but I can't seem to google up any hints.
>
> With many thanks,
>
> Greg Jefferis.
>
> [1] http://github.com/jefferislab/nat.nblast 
> https://cran.r-project.org/package=nat.nblast
> [2]
>
> @article{Costa:2016aa,
> 	Author = {Costa, Marta and Manton, James D and Ostrovsky, Aaron D and 
> Prohaska, Steffen and Jefferis, Gregory S X E},
> 	Doi = {10.1016/j.neuron.2016.06.012},
> 	Journal = {Neuron},
> 	Month = {Jul},
> 	Number = {2},
> 	Pages = {293-311},
> 	Title = {NBLAST: Rapid, Sensitive Comparison of Neuronal Structure 
> and Construction of Neuron Family Databases},
> 	Volume = {91},
> 	Year = {2016}}
>
> [3] https://rdrr.io/github/ropensci/RefManageR/man/toBiblatex.html
>
>
> --
> Gregory Jefferis
> Division of Neurobiology
> MRC Laboratory of Molecular Biology
> Francis Crick Avenue
> Cambridge Biomedical Campus
> Cambridge, CB2 OQH, UK
>
> http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
> http://jefferislab.org
> http://www.zoo.cam.ac.uk/departments/connectomics
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Making a package CITATION file from BibTeX
Achim Zeileis