Skip to content

Commit

Permalink
Merge pull request #84 from ropensci/autocitation
Browse files Browse the repository at this point in the history
Add option for auto creation of inst/CITATION
  • Loading branch information
dieghernan authored Jan 18, 2025
2 parents aae75f8 + 8acbbcb commit 8ded758
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cff-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
uses: actions/checkout@v4

- name: Validate CITATION.cff
uses: dieghernan/cff-validator@main
uses: dieghernan/cff-validator@v4

16 changes: 0 additions & 16 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ jobs:
covr::to_cobertura(cov)
shell: Rscript {0}

- name: Create Junit Report
if: always()
run: |
test_out <- path.expand(file.path(getwd(), "junit.xml"))
testthat::test_local(reporter = testthat::JunitReporter$new(test_out))
shell: Rscript {0}

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./junit.xml
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload coverage report
uses: codecov/codecov-action@v5
with:
Expand Down
26 changes: 13 additions & 13 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message: 'To cite package "cffr" in publications use:'
type: software
license: GPL-3.0-or-later
title: 'cffr: Generate Citation File Format (''cff'') Metadata for R Packages'
version: 1.1.1
version: 1.1.1.9000
doi: 10.21105/joss.03900
identifiers:
- type: doi
Expand Down Expand Up @@ -98,7 +98,7 @@ references:
institution:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2024'
year: '2025'
version: '>= 4.0.0'
- type: software
title: cli
Expand All @@ -110,7 +110,7 @@ references:
- family-names: Csárdi
given-names: Gábor
email: [email protected]
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.cli
version: '>= 2.0.0'
- type: software
Expand All @@ -128,7 +128,7 @@ references:
- family-names: Hester
given-names: Jim
email: [email protected]
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.desc
version: '>= 1.3.0'
- type: software
Expand All @@ -142,7 +142,7 @@ references:
given-names: Jeroen
email: [email protected]
orcid: https://orcid.org/0000-0002-4035-0289
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.jsonlite
version: '>= 1.7.2'
- type: software
Expand All @@ -161,7 +161,7 @@ references:
given-names: Mathias
- family-names: Poberezkin
given-names: Evgeny
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.jsonvalidate
version: '>= 1.1.0'
- type: software
Expand Down Expand Up @@ -198,7 +198,7 @@ references:
given-names: Zhian N.
- family-names: Gao
given-names: Charlie
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.yaml
version: '>= 2.2.1'
- type: software
Expand All @@ -216,7 +216,7 @@ references:
given-names: Diego
email: [email protected]
orcid: https://orcid.org/0000-0001-8457-4658
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.bibtex
version: '>= 0.5.0'
- type: software
Expand All @@ -230,7 +230,7 @@ references:
given-names: Yihui
email: [email protected]
orcid: https://orcid.org/0000-0003-0645-5666
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.knitr
- type: software
title: lifecycle
Expand All @@ -246,7 +246,7 @@ references:
given-names: Hadley
email: [email protected]
orcid: https://orcid.org/0000-0003-4757-117X
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.lifecycle
- type: software
title: rmarkdown
Expand Down Expand Up @@ -290,7 +290,7 @@ references:
given-names: Richard
email: [email protected]
orcid: https://orcid.org/0000-0003-3925-190X
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.rmarkdown
- type: software
title: testthat
Expand All @@ -302,7 +302,7 @@ references:
- family-names: Wickham
given-names: Hadley
email: [email protected]
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.testthat
version: '>= 3.0.0'
- type: software
Expand All @@ -328,6 +328,6 @@ references:
given-names: Andy
email: [email protected]
orcid: https://orcid.org/0000-0002-7840-692X
year: '2024'
year: '2025'
doi: 10.32614/CRAN.package.usethis

2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cffr
Title: Generate Citation File Format ('cff') Metadata for R Packages
Version: 1.1.1
Version: 1.1.1.9000
Authors@R: c(
person("Diego", "Hernangómez", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8457-4658")),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# cffr (development version)

- New parameter `r_citation` in `cff_write()`. When it is set to `TRUE` a
**R** citation file (`inst/CITATION`) would be generated/updated with the
information of the generated `CITATION.cff` file. **No backup copy would be
created**, for more control use `cff_write_citation()` (#79).

# cffr 1.1.1

- Adapt extraction of orcid to **R \> 4.4.1**.
Expand Down
36 changes: 33 additions & 3 deletions R/cff_write.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#'
#' @param outfile The name and path of the `CITATION.cff` to be created.
#'
#' @param r_citation Logical `TRUE/FALSE`. On `TRUE` the **R** package citation
#' (i.e. `inst/CITATION`) would be created or updated.
#' **No backup copy would be created**, for more control use
#' [cff_write_citation()].
#'
#' @param verbose Logical `TRUE/FALSE`. On `TRUE` the function would display
#' informative messages.
#'
Expand Down Expand Up @@ -65,9 +70,9 @@
#'
cff_write <- function(x, outfile = "CITATION.cff", keys = list(),
cff_version = "1.2.0", gh_keywords = TRUE,
dependencies = TRUE, validate = TRUE,
verbose = TRUE, authors_roles = c("aut", "cre"),
encoding = "UTF-8") {
r_citation = FALSE, dependencies = TRUE,
validate = TRUE, verbose = TRUE,
authors_roles = c("aut", "cre"), encoding = "UTF-8") {
# # On missing use NULL
if (missing(x)) x <- getwd()

Expand Down Expand Up @@ -136,5 +141,30 @@ cff_write <- function(x, outfile = "CITATION.cff", keys = list(),
cff_validate(outfile, verbose)
}

# Issue #79
auto_r_citation(
r_citation = r_citation,
outfile = outfile, verbose = verbose
)

return(invisible(citat))
}


auto_r_citation <- function(r_citation = TRUE,
outfile = "CITATION.cff", verbose = TRUE) {
# Do nothing
if (isFALSE(r_citation)) {
return(invisible(NULL))
}

# Else
if (verbose) {
cli::cat_rule("Updating inst/CITATION file", col = "cyan", line = 2)
}
cffobj <- cff_read(outfile)
fpath <- "./inst/CITATION"
if (file.exists(fpath)) unlink(fpath)

cff_write_citation(cffobj, file = fpath, verbose = verbose)
}
2 changes: 1 addition & 1 deletion R/utils-alerts.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ write_lines_msg <- function(lines, file, verbose, append) {
fh <- file(file, encoding = "UTF-8", open = ifelse(append, "a+", "w+"))
on.exit(if (isOpen(fh)) close(fh))
if (verbose) {
cli::cli_alert_info("Writing {length(lines)} entr{?y/ies} ...")
cli::cli_alert_info("Writing {length(lines[lines != ''])} entr{?y/ies} ...")
}

writeLines(lines, fh)
Expand Down
Loading

0 comments on commit 8ded758

Please sign in to comment.