ropensci / cffr

Generate Citation File Format (cff) Metadata for R Packages
https://docs.ropensci.org/cffr/
GNU General Public License v3.0
25 stars 3 forks source link

Feature request: Add url key to write_citation() function #58

Closed larnsce closed 1 year ago

larnsce commented 1 year ago

Goal

I would like to include the URL of the GitHub pages site for the website that is build with pkgdown R package in the inst/CITATION file.

Problem

Adding the key url to cff_create() adds the URL to the CITATION.cff, but the write_citation() function does not use this key for the final inst/CITATION file.

Example

# install.packages("cffr")
library(cffr)

packageVersion("cffr")

# Download a DESCRIPTION file
tmp <- file.path(tempdir(), "DESCRIPTION")

download.file("https://raw.githubusercontent.com/openwashdata/wasteskipsblantyre/main/DESCRIPTION",
              tmp,
              quiet = TRUE
)

# Hard code doi
doi <- "10.5281/zenodo.6470427"

# get the year
year <- format(Sys.time(), "%Y")

# creates CFF with all author roles
mod_cff <- cff_create(tmp, 
                      dependencies = FALSE,
                      keys = list("doi" = doi,
                                  "url" = "https://openwashdata.github.io/wasteskipsblantyre/",
                                  "date-released" = Sys.Date()))

# 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")

write_citation("CITATION.cff", file = path_cit)

# By last, read the citation
cat(readLines(path_cit), sep = "\n")

# Start of inst/CITATION
utils::readCitationFile("inst/CITATION")
dieghernan commented 1 year ago

Hi @larnsce

Sorry I don't see the issue you mentioned, the url is indeed in the inst/CITATION file. Maybe I am missing something here:

library(cffr)

packageVersion("cffr")
#> [1] '0.5.0'

# Download a DESCRIPTION file
tmp <- file.path(tempdir(), "DESCRIPTION")

download.file("https://raw.githubusercontent.com/openwashdata/wasteskipsblantyre/main/DESCRIPTION",
  tmp,
  quiet = TRUE
)

# Hard code doi
doi <- "10.5281/zenodo.6470427"

# get the year
year <- format(Sys.time(), "%Y")

# creates CFF with all author roles
mod_cff <- cff_create(tmp,
  dependencies = FALSE,
  keys = list(
    "doi" = doi,
    "url" = "https://openwashdata.github.io/wasteskipsblantyre/",
    "date-released" = Sys.Date()
  )
)

# writes the CFF file
cff_write(mod_cff)
#> v 'CITATION.cff' generated
#> == Validating cff ==============================================================
#> v Congratulations! 'CITATION.cff' is valid

# 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")

write_citation("CITATION.cff", file = path_cit)
#> i Creating directory 'inst'
#> i Writing 1 entry ...
#> v Results written to 'inst/CITATION'

Here we see that inst/CITATION has url = "https://openwashdata.github.io/wasteskipsblantyre/", that is the url you provided:

# By last, read the citation
cat(readLines(path_cit), sep = "\n")
#> 
#> bibentry(bibtype = "Misc",
#>          key = "yesayamsuku",
#>          title = "wasteskipsblantyre: Locations of Public Waste Skips in Blantyre, Malawi",
#>          author = c(person(given = "Mabvuto",
#>                            family = "Yesaya"),
#>                     person(given = "Limbani",
#>                            family = "Msuku"),
#>                     person(given = "Elizabeth",
#>                            family = "Tilley"),
#>                     person(given = "Sebastian Camilo",
#>                            family = "Loos")),
#>          year = "2023",
#>          doi = "10.5281/zenodo.6470427",
#>          url = "https://openwashdata.github.io/wasteskipsblantyre/",
#>          abstract = "An R data package containing the locations of public waste skips in Blantyre, Malawi.",
#>          version = "0.0.2")

# Start of inst/CITATION
cite <- utils::readCitationFile("inst/CITATION")

cite
#> 
#> Yesaya M, Msuku L, Tilley E, Loos S (2023). "wasteskipsblantyre:
#> Locations of Public Waste Skips in Blantyre, Malawi." doi:
#> 10.5281/zenodo.6470427 (URL: https://doi.org/10.5281/zenodo.6470427),
#> <URL: https://openwashdata.github.io/wasteskipsblantyre/>.
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Misc{yesayamsuku,
#>     title = {wasteskipsblantyre: Locations of Public Waste Skips in Blantyre, Malawi},
#>     author = {Mabvuto Yesaya and Limbani Msuku and Elizabeth Tilley and Sebastian Camilo Loos},
#>     year = {2023},
#>     doi = {10.5281/zenodo.6470427},
#>     url = {https://openwashdata.github.io/wasteskipsblantyre/},
#>     abstract = {An R data package containing the locations of public waste skips in Blantyre, Malawi.},
#>     version = {0.0.2},
#>   }

print(cite, style = "text")
#> Yesaya M, Msuku L, Tilley E, Loos S (2023). "wasteskipsblantyre:
#> Locations of Public Waste Skips in Blantyre, Malawi." doi:
#> 10.5281/zenodo.6470427 (URL: https://doi.org/10.5281/zenodo.6470427),
#> <URL: https://openwashdata.github.io/wasteskipsblantyre/>.

Created on 2023-08-02 with reprex v2.0.2

larnsce commented 1 year ago

Yes, you are right. I have tried again and cannot reproduce it anymore. Sorry for wasting your time.