ropensci / handlr

convert among citation formats
https://docs.ropensci.org/handlr
Other
38 stars 4 forks source link

Support for CFF v1.2.0 #24

Closed dieghernan closed 2 years ago

dieghernan commented 2 years ago
Session Info ```r R version 4.1.0 (2021-05-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042) Matrix products: default locale: [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 LC_MONETARY=Spanish_Spain.1252 [4] LC_NUMERIC=C LC_TIME=Spanish_Spain.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] handlr_0.3.0 loaded via a namespace (and not attached): [1] Rcpp_1.0.7 pillar_1.6.2 compiler_4.1.0 prettyunits_1.1.1 remotes_2.4.0 [6] tools_4.1.0 testthat_3.0.4 digest_0.6.27 pkgbuild_1.2.0 pkgload_1.2.1 [11] tibble_3.1.4 lifecycle_1.0.0 jsonlite_1.7.2 evaluate_0.14 memoise_2.0.0 [16] pkgconfig_2.0.3 rlang_0.4.11 rstudioapi_0.13 cli_3.0.1 crul_1.1.0 [21] curl_4.3.2 yaml_2.2.1 xfun_0.25 fastmap_1.1.0 withr_2.4.2 [26] xml2_1.3.2 knitr_1.33 vctrs_0.3.8 desc_1.3.0 fs_1.5.0 [31] devtools_2.4.2 triebeard_0.3.0 rprojroot_2.0.2 glue_1.4.2 httpcode_0.3.0 [36] R6_2.5.1 processx_3.5.2 fansi_0.5.0 rmarkdown_2.10 sessioninfo_1.1.1 [41] purrr_0.3.4 callr_3.7.0 magrittr_2.0.1 urltools_1.7.3 ps_1.6.0 [46] ellipsis_0.3.2 htmltools_0.5.2 usethis_2.0.1 mime_0.11 utf8_1.2.2 [51] cachem_1.0.6 crayon_1.4.1 ```

Hi:

There is a new version of CFF (released on 31 May 2021) with some important changes (see changelog)

Among other changes, CFF v1.2.0 does not require some fields:

version, date-released no longer required elements of a minimal CFF

This is causing an error when trying to convert CFF v1.2.0 to another format, see a minimal example:

``` r
#devtools::install_github("dieghernan/cffr")

library(cffr)

# Minimal cff structure as per v1.2.0

minimal <- cff()

minimal
#> authors:
#> - family-names: Druskat
#>   given-names: Stephan
#> cff-version: 1.2.0
#> message: If you use this software, please cite it using these metadata.
#> title: My Research Software

# Validate against the official schema.json v1.2.0 with {jsonvalidate}
# https://github.com/citation-file-format/citation-file-format/blob/main/schema.json

cff_validate(minimal)
#> 
#> cff_validate results-----
#> Congratulations! This cff object is valid

# Try to parse with handlr

library(handlr)
#> Warning: package 'handlr' was built under R version 4.1.1
library(yaml)

tohandlr <- cff_reader(as.yaml(minimal))
#> Error: 'date-released' is required

# Fix by forcing required arguments only in v1.1.0
# Force version and date-released
fix <- minimal
fix$`date-released` <- "2010-01-01"
fix$version <- "beta"

cff_validate(fix)
#> 
#> cff_validate results-----
#> Congratulations! This cff object is valid

tohandlr <- cff_reader(as.yaml(fix))
unclass(tohandlr)
#> $cff_version
#> [1] "1.2.0"
#> 
#> $message
#> [1] "If you use this software, please cite it using these metadata."
#> 
#> $id
#> NULL
#> 
#> $type
#> [1] "SoftwareSourceCode"
#> 
#> $citeproc_type
#> [1] "article-journal"
#> 
#> $bibtex_type
#> [1] "misc"
#> 
#> $ris_type
#> [1] "COMP"
#> 
#> $resource_type_general
#> [1] "Software"
#> 
#> $identifier
#> NULL
#> 
#> $doi
#> NULL
#> 
#> $b_url
#> NULL
#> 
#> $title
#> [1] "My Research Software"
#> 
#> $author
#> $author[[1]]
#> $author[[1]]$type
#> [1] "Person"
#> 
#> $author[[1]]$name
#> [1] "Stephan Druskat"
#> 
#> $author[[1]]$givenName
#> [1] "Stephan"
#> 
#> $author[[1]]$familyName
#> [1] "Druskat"
#> 
#> $author[[1]]$orcid
#> [1] ""
#> 
#> 
#> 
#> $date_published
#> [1] "2010-01-01"
#> 
#> $software_version
#> [1] "beta"
#> 
#> $description
#> $description$text
#> NULL
#> 
#> 
#> $license
#> $license$id
#> NULL
#> 
#> 
#> $keywords
#> NULL
#> 
#> $state
#> [1] "not_found"
#> 
#> $references
#> NULL
#> 
#> attr(,"from")
#> [1] "cff"
#> attr(,"source_type")
#> [1] "string"
#> attr(,"file")
#> [1] ""
#> attr(,"many")
#> [1] FALSE

Created on 2021-09-15 by the reprex package (v2.0.0)