Skip to content

Commit

Permalink
Add auto creation of inst/CITATION
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Jan 17, 2025
1 parent c04d280 commit d058497
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 55 deletions.
29 changes: 16 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,10 @@ references:
given-names: Jeroen
email: [email protected]
orcid: https://orcid.org/0000-0002-4035-0289
year: '2024'
year: '2025'
identifiers:
- type: url
value: https://arxiv.org/abs/1403.2805
doi: 10.32614/CRAN.package.jsonlite
version: '>= 1.7.2'
- type: software
Expand All @@ -161,7 +164,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 +201,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 +219,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 +233,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 +249,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 +293,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 +305,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 +331,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 d058497

Please sign in to comment.