r-lib / usethis

Set up commonly used 📦 components
https://usethis.r-lib.org/
Other
862 stars 284 forks source link

Input DOI to use_citation() and get a ready to use CITATION file #1812

Closed phamdn closed 3 months ago

phamdn commented 1 year ago

Filling every field in the CITATION template is tiring. It would be great if one can insert a DOI in use_citation() and get a file with full metadata to use directly for R package.

For example, here is the CITATION file of lme4: https://github.com/lme4/lme4/blob/master/inst/CITATION

bibentry(bibtype = "Article",
  title        = "Fitting Linear Mixed-Effects Models Using {lme4}",
  author       = c(person(given = "Douglas",
                          family = "Bates"),
                   person(given = "Martin",
                          family = "M{\\\"a}chler"),
                   person(given = "Ben",
                          family = "Bolker"),
                   person(given = "Steve",
                          family = "Walker")),
  journal      = "Journal of Statistical Software",
  year         = "2015",
  volume       = "67",
  number       = "1",
  pages        = "1--48",
  doi          = "10.18637/jss.v067.i01",

  header       = "To cite lme4 in publications use:",
  textVersion  =
  paste("Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015).",
        "Fitting Linear Mixed-Effects Models Using lme4.",
        "Journal of Statistical Software, 67(1), 1-48.",
        "doi:10.18637/jss.v067.i01.")
)

If I was the developer of this package, how could I make this file automatically in the first place with the DOI 10.18637/jss.v067.i01?

Citation management software such as Zotero can make BibTex file easily

@article{bates2015,
    title = {Fitting {Linear} {Mixed}-{Effects} {Models} {Using} lme4},
    volume = {67},
    copyright = {Copyright (c) 2015 Douglas Bates, Martin Mächler, Ben Bolker, Steve Walker},
    issn = {1548-7660},
    url = {https://doi.org/10.18637/jss.v067.i01},
    doi = {10.18637/jss.v067.i01},
    abstract = {Maximum likelihood or restricted maximum likelihood (REML) estimates of the parameters in linear mixed-effects models can be determined using the lmer function in the lme4 package for R. As for most model-fitting functions in R, the model is described in an lmer call by a formula, in this case including both fixed- and random-effects terms. The formula and data together determine a numerical representation of the model from which the profiled deviance or the profiled REML criterion can be evaluated as a function of some of the model parameters. The appropriate criterion is optimized, using one of the constrained optimization functions in R, to provide the parameter estimates. We describe the structure of the model, the steps in evaluating the profiled deviance or REML criterion, and the structure of classes or types that represents such a model. Sufficient detail is included to allow specialization of these structures by users who wish to write functions to fit specialized linear mixed models, such as models incorporating pedigrees or smoothing splines, that are not easily expressible in the formula language used by lmer.},
    language = {en},
    urldate = {2023-03-17},
    journal = {Journal of Statistical Software},
    author = {Bates, Douglas and Mächler, Martin and Bolker, Ben and Walker, Steve},
    month = oct,
    year = {2015},
    keywords = {linear mixed models, Cholesky decomposition, penalized least squares, sparse matrix methods},
    pages = {1--48},
    file = {},
}

which is similar to the output of citation("lme4"). My question could be translated into, how to reverse this process to get the code inside CITATION file.

To cite lme4 in publications use:

  Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models
  Using lme4. Journal of Statistical Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.

A BibTeX entry for LaTeX users is

  @Article{,
    title = {Fitting Linear Mixed-Effects Models Using {lme4}},
    author = {Douglas Bates and Martin M{\"a}chler and Ben Bolker and Steve Walker},
    journal = {Journal of Statistical Software},
    year = {2015},
    volume = {67},
    number = {1},
    pages = {1--48},
    doi = {10.18637/jss.v067.i01},
  }

Thank you very much.

hadley commented 1 year ago

Unless you can suggest an existing R package that can go from a DOI to a citation, I think this is out of scope for usethis.

jennybc commented 3 months ago

Until someone suggests a way to go from DOI to the citation data, this doesn't seem to be going anywhere.