Skip to content

Commit

Permalink
Merge pull request #75 from ropensci/crandoi
Browse files Browse the repository at this point in the history
Recognize CRAN DOI
  • Loading branch information
dieghernan committed Jun 13, 2024
2 parents 17f18ee + 94a1160 commit f3cb97b
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 51 deletions.
14 changes: 14 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license: GPL-3.0-or-later
title: 'cffr: Generate Citation File Format (''cff'') Metadata for R Packages'
version: 1.0.1.9000
doi: 10.21105/joss.03900
identifiers:
- type: doi
value: 10.32614/CRAN.package.cffr
abstract: The Citation File Format version 1.2.0 <https://doi.org/10.5281/zenodo.5171937>
is a human and machine readable file format which provides citation metadata for
software. This package provides core utilities to generate and validate this metadata.
Expand Down Expand Up @@ -108,6 +111,7 @@ references:
given-names: Gábor
email: csardi.gabor@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.cli
version: '>= 2.0.0'
- type: software
title: desc
Expand All @@ -125,6 +129,7 @@ references:
given-names: Jim
email: james.f.hester@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.desc
version: '>= 1.3.0'
- type: software
title: jsonlite
Expand All @@ -141,6 +146,7 @@ references:
identifiers:
- type: url
value: https://arxiv.org/abs/1403.2805
doi: 10.32614/CRAN.package.jsonlite
version: '>= 1.7.2'
- type: software
title: jsonvalidate
Expand All @@ -159,6 +165,7 @@ references:
- family-names: Poberezkin
given-names: Evgeny
year: '2024'
doi: 10.32614/CRAN.package.jsonvalidate
version: '>= 1.1.0'
- type: software
title: yaml
Expand Down Expand Up @@ -193,6 +200,7 @@ references:
- family-names: Kamvar
given-names: Zhian N.
year: '2024'
doi: 10.32614/CRAN.package.yaml
version: '>= 2.2.1'
- type: software
title: bibtex
Expand All @@ -210,6 +218,7 @@ references:
email: diego.hernangomezherrero@gmail.com
orcid: https://orcid.org/0000-0001-8457-4658
year: '2024'
doi: 10.32614/CRAN.package.bibtex
version: '>= 0.5.0'
- type: software
title: knitr
Expand All @@ -223,6 +232,7 @@ references:
email: xie@yihui.name
orcid: https://orcid.org/0000-0003-0645-5666
year: '2024'
doi: 10.32614/CRAN.package.knitr
- type: software
title: lifecycle
abstract: 'lifecycle: Manage the Life Cycle of your Package Functions'
Expand All @@ -238,6 +248,7 @@ references:
email: hadley@posit.co
orcid: https://orcid.org/0000-0003-4757-117X
year: '2024'
doi: 10.32614/CRAN.package.lifecycle
- type: software
title: rmarkdown
abstract: 'rmarkdown: Dynamic Documents for R'
Expand Down Expand Up @@ -281,6 +292,7 @@ references:
email: rich@posit.co
orcid: https://orcid.org/0000-0003-3925-190X
year: '2024'
doi: 10.32614/CRAN.package.rmarkdown
- type: software
title: testthat
abstract: 'testthat: Unit Testing for R'
Expand All @@ -292,6 +304,7 @@ references:
given-names: Hadley
email: hadley@posit.co
year: '2024'
doi: 10.32614/CRAN.package.testthat
version: '>= 3.0.0'
- type: software
title: usethis
Expand All @@ -317,4 +330,5 @@ references:
email: andy.teucher@posit.co
orcid: https://orcid.org/0000-0002-7840-692X
year: '2024'
doi: 10.32614/CRAN.package.usethis

9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# cffr (development version)

- Now **cffr** adds automatically dois to packages on **CRAN** (e.g.
<https://doi.org/10.32614/CRAN.package.cffr>):
- If the package has a `CITATION` file providing a doi, the `CITATION` doi
would be used as the main `CITATION.cff` `doi` and the **CRAN** doi
would be added as an `identifier`.
- Otherwise, **CRAN** doi would be used as `doi`.
- When extracting dependencies (e.g `cff_create(dependencies = TRUE)` and
the package dependency is on **CRAN**, the **CRAN** doi would be used
for the dependency in the `references` key.
- Extract `commit` from `RemoteSha`.

# cffr 1.0.1
Expand Down
3 changes: 2 additions & 1 deletion R/cff_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ cff_read_description <- function(path, cff_version = "1.2.0",
contact = get_desc_contacts(pkg),
keywords = get_desc_keywords(pkg),
license = unlist(get_desc_license(pkg)),
commit = get_desc_sha(pkg)
commit = get_desc_sha(pkg),
doi = get_desc_doi(pkg)
)

if (gh_keywords) {
Expand Down
10 changes: 10 additions & 0 deletions R/utils-cff_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,13 @@ get_desc_sha <- function(pkg) {

sha
}

get_desc_doi <- function(pkg) {
pkg <- pkg$get("Package")
if (is.null(search_on_repos(pkg))) {
return(NULL)
}

doi <- paste0("10.32614/CRAN.package.", pkg)
clean_str(doi)
}
25 changes: 23 additions & 2 deletions R/utils-create.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ merge_desc_cit <- function(cffobj, citobj) {
if (is.null(citobj)) {
return(cffobj)
}
# Play with cran DOI
cran_doi <- NULL
has_cran_doi <- FALSE
if (all(!is.null(cffobj$doi), grepl("CRAN", cffobj$doi))) {
has_cran_doi <- TRUE
cran_doi <- cffobj$doi
# First the citation object
cffobj$doi <- NULL
}

# Add doi from citation if missing
if (is.null(cffobj$doi)) {
Expand All @@ -21,8 +30,16 @@ merge_desc_cit <- function(cffobj, citobj) {


# Merge identifiers
oldids <- cffobjend$identifiers
cffobjend$identifiers <- c(citobj[[1]]$identifiers, oldids)
merged_ids <- c(citobj[[1]]$identifiers, cffobjend$identifiers)


if (has_cran_doi) {
cranid <- as_cff(list(
list(type = "doi", value = clean_str(cran_doi))
))
merged_ids <- c(cranid, merged_ids)
}
cffobjend$identifiers <- merged_ids

# Reorder
cffobjfinal <- c(
Expand Down Expand Up @@ -136,6 +153,10 @@ get_dependencies <- function(desc_path,
# Avoid cluttering the output
mod$abstract <- mod$title
mod$title <- n$package
# If on CRAN add CRAN DOI
if (!is.null(n$package)) {
mod$doi <- paste0("10.32614/CRAN.package.", n$package)
}
}

mod$type <- "software"
Expand Down
4 changes: 2 additions & 2 deletions R/utils-schema.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ cff_schema_keys <- function(sorted = FALSE) {
"title",
"version",
"doi",
"identifiers",
"abstract",
"authors",
"preferred-citation",
"repository",
"repository-artifact",
"repository-code",
"commit",
"url",
"date-released",
"contact",
"keywords",
"references",
"commit",
"identifiers",
"license-url"
)
}
Expand Down
Loading

0 comments on commit f3cb97b

Please sign in to comment.