Last active
March 26, 2024 13:14
-
-
Save larnsce/dccdb26762837618c6dda82a5614b584 to your computer and use it in GitHub Desktop.
Code to add all author roles and DOI from R Package documentation DESCRIPTION file to a CITATION.cff and generate inst/CITATION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install.packages("cffr") | |
library(cffr) | |
packageVersion("cffr") | |
# Hard code doi | |
doi <- "10.5281/zenodo.6470427" | |
# creates CFF with all author roles | |
mod_cff <- cff_create("DESCRIPTION", | |
dependencies = FALSE, | |
keys = list("doi" = doi, | |
"date-released" = Sys.Date())) | |
# Remove the preferred-citation key | |
mod_cff$`preferred-citation` <- NULL | |
# writes the CFF file | |
cff_write(mod_cff) | |
# Now write a CITATION file from the CITATION.cff file | |
# Use inst/CITATION instead (the default if not provided) | |
path_cit <- file.path("inst/CITATION") | |
a_cff <- cff_read(path = "CITATION.cff") | |
cff_write_citation(a_cff, file = path_cit) | |
# By last, read the citation | |
cat(readLines(path_cit), sep = "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment