knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(authoritative)
This package has two main categories of functionality:
DESCRIPTION
file of R packages, or the equivalent data provided as a data.frame
by the {pkgsearch}
package,
to extract authors from the Author
or Authors@R
fields.
These features are only useful in the context of the R package ecosystem.R package authors can be specified in two ways in the DESCRIPTION
file.
Author
fieldThe authors can be listed in the Author
field, as free text.
However, this method is now actively discouraged by CRAN, and many R user communities, such as rOpenSci.
We would for example have:
Author: Ada Lovelace and Charles Babbage
Because this is free-text, it could be formatted in many different ways,
and it is hard to programmatically extract the names.
The parse_authors()
function provided by the package is designed to split at common delimiter and clean common extra words.
parse_authors("Ada Lovelace and Charles Babbage") parse_authors("Ada Lovelace, Charles Babbage") parse_authors("Ada Lovelace with contributions from Charles Babbage") parse_authors("Ada Lovelace, Charles Babbage, et al.")
Authors@R
fieldThe authors can also be listed in Authors@R
field as a string containing R code that generates a vector of person
objects.
This is the most modern and recommended way to specify authors in the DESCRIPTION
file.
Authors@R: c(
person("Ada Lovelace", role = c("aut", "cre"), email = "ada@email.com"),
person("Charles Babbage", role = "aut")
)
auts <- parse_authors_r("c( person('Ada Lovelace', role = c('aut', 'cre'), email = 'ada@email.com'), person('Charles Babbage', role = 'aut') )") class(auts) str(auts) print(auts)
If we only want the names, we can use the format.person()
base R function:
format(auts, include = c("given", "family"))
We can now take the list of authors extracted from the previous step, or an independently gathered list of names, and clean and deduplicate it.
The expand_names()
function can be used to expand differently abbreviated names to a common form, passed in the expanded
argument:
expand_names(c("Ada Lovelace", "A Lovelace"), expanded = "Ada Lovelace")
However, a common pattern is to pass the vector to clean itself in expanded
.
This way, you can harmonize names to their longest form in the vector, even if you do not know the full name of all authors in advance:
my_names <- c("Ada Lovelace", "A Lovelace", "Charles Babbage") expand_names(my_names, my_names)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.