ropensci / cffr

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

error message attempting to write CITATION.cff file from BibTeX file #71

Closed iembry closed 4 months ago

iembry commented 4 months ago

I previously used version 0.2.0 of the cffr package with the following code to create a CITATION.cff file from a BibTeX file:

library(rbibutils)
library(cffr)

# read in the References stored in a JabRef database
bib <- readBib("./inst/references/Data_References.bib")

# create the cff object
jab_adverse_reactions_citation <- cff_create()

# convert the bibentry object to a cff object (for a proper citation)
bib_to_cff <- cff_parse_citation(bib)

# produce the reference keys from the bibentry object
refkeys <- list(references = bib_to_cff)

# Write the package citation as a .cff file
cff_write(jab_adverse_reactions_citation, keys = refkeys)

However, with the current version 1.0.1, the aforementioned workflow is no longer possible. I have attempted to read the documentation and attempt a new strategy to get the same results, but to no avail. Please refer to the error message below:

# read in the References stored in a JabRef database
jab_adverse_reactions_citation <- cff_read("./inst/references/Data_References.bib")

# > class(jab_adverse_reactions_citation)
# [1] "cff_ref_lst" "cff"

# > cff_write(jab_adverse_reactions_citation)
# Error in x[[i]] : recursive indexing failed at level 2

What's the correct method to create a CITATION.cff file from a BibTeX file?

Thank you.

Irucka

dieghernan commented 4 months ago

Hi @iembry

Note that these lines:

# > cff_write(jab_adverse_reactions_citation)
# Error in x[[i]] : recursive indexing failed at level 2

are trying to create a full CFF from a reference list cff_ref_lst, but no for a full CFF list. See https://docs.ropensci.org/cffr/reference/cff_class.html#sub-classes for more info.

With the new API you may want to make these changes:

See an example, you would need to adjust the paths since I created this cff from a stand-alone project (not inside the package project):

library(cffr)

bib_path <- system.file("references/Data_References.bib",
  package = "jab.adverse.reactions"
)

# read in the References stored in a JabRef database
# For an in-development package use bib <- cff_read("./inst/references/Data_References.bib")
bib <- cff_read(bib_path)

# create the cff object, we can use native pipe now (|>)
# For an in-development package use jab_adverse_reactions_citation <- cff_create() |> ...
jab_adverse_reactions_citation <- cff_create("jab.adverse.reactions") |>
  # Use cff_modify: this would override original references
  cff_modify(references = bib)

# Write the package citation as a .cff file
temp_cff <- tempfile(fileext = ".cff")
cff_write(jab_adverse_reactions_citation, temp_cff)
#> ✔ '/tmp/RtmphjeHQ2/file6dd403d6eec.cff' generated
#> ══ Validating cff ══════════════════════════════════════════════════════════════
#> ✔ Congratulations! '/tmp/RtmphjeHQ2/file6dd403d6eec.cff' is valid
# preview
cff_read(temp_cff)
CFF file preview ``` r #> cff-version: 1.2.0 #> message: 'To cite package "jab.adverse.reactions" in publications use:' #> type: software #> license: GPL-3.0-or-later #> title: 'jab.adverse.reactions: Possible Adverse Events/Reactions from the Vaccinations/Experimental #> Gene Therapies' #> version: 1.0.3 #> abstract: Provides data about the possible adverse events/reactions resulting from #> being injected with a vaccine/experimental gene therapy. Currently, this data set #> only includes information from six reference sources. Refer to the CITATION.cff #> file for the complete citations of the reference sources. For information about #> vaccination$/immunization$ hazards, visit , #> , , #> and . #> authors: #> - family-names: Embry #> given-names: Irucka #> email: iembry@ecoccs.com #> preferred-citation: #> type: manual #> title: 'jab.adverse.reactions: Possible Adverse Events/Reactions from the Vaccinations/Experimental #> Gene Therapies' #> authors: #> - family-names: Embry #> given-names: Irucka #> email: iembry@ecoccs.com #> year: '2022' #> url: https://gitlab.com/iembry/jab.adverse.reactions #> abstract: Provides data about the possible adverse events/reactions resulting from #> being injected with a vaccine/experimental gene therapy. Currently, the data is #> only from three reference sources. Refer to the Citation file for the reference #> information. For information about vaccination$/immunization$ hazards, visit , #> , , #> and . #> version: 1.0.1 #> repository: https://CRAN.R-project.org/package=jab.adverse.reactions #> repository-code: https://gitlab.com/iembry/jab.adverse.reactions #> url: https://gitlab.com/iembry/jab.adverse.reactions #> date-released: '2023-09-20' #> contact: #> - family-names: Embry #> given-names: Irucka #> email: iembry@ecoccs.com #> references: #> - type: report #> title: 5.3.6 Cumulative Analysis of Post-Authorization Adverse Event Reports of #> PF-07302048 (BNT162B2) Received Through 28-Feb-2021 Report #> authors: #> - family-names: Pfizer #> given-names: Worldwide Safety #> institution: #> name: Pfizer #> year: '2021' #> url: https://phmpt.org/wp-content/uploads/2021/11/5.3.6-postmarketing-experience.pdf #> - type: article #> title: Neuritis and Multiple Neuritis Following Serum Therapy #> authors: #> - family-names: Wilson #> given-names: George #> - family-names: Hadden #> given-names: Samuel B. #> journal: JAMA #> year: '1932' #> volume: '98' #> issue: '2' #> month: '1' #> issn: 1538-3598 #> abstract: With the increased use of therapeutic serums in the past twenty years, #> much has been written of the various manifestations of anaphylaxis. Urticaria, #> arthralgia, adenopathy and cardiac collapse are well known complications of serum #> therapy. Coma and occasionally death have been reported following serum injection. #> Many reports of multiple neuritis and myelitis following the use of Pasteur treatment #> have appeared, and encephalitis following vaccination is well known. Another unpleasant #> complication of prophylactic efforts, and fortunately one less frequently seen, #> is multiple neuritis. In 1912, Thaon reported a case in which paralysis of the #> serratus magnus and other muscles developed following serum sickness due to the #> injection of 10 cc. of tetanus antitoxin. In 1915, Richardson reported a case #> of severe tetanus with recovery, which was followed by a pronounced multiple neuritis #> that he attributed to the action of the tetanus toxin. Dyke in 1918 wrote on neuritis... #> doi: 10.1001/jama.1932.02730280031007 #> url: https://jamanetwork.com/journals/jama/article-abstract/1153665 #> start: 123-125 #> - type: generic #> title: October 22, 2020 Meeting Presentation #> authors: #> - family-names: Anderson #> given-names: Steve #> medium: 'US Food and Drug Administration (FDA): Vaccines and Related Biological #> Products Advisory Committee' #> month: '10' #> year: '2020' #> url: https://web.archive.org/web/20201126033341/https://www.fda.gov/media/143557/download #> - type: article #> title: Serum Shock and Serum Reaction #> authors: #> - family-names: Iyengar #> given-names: K. G. #> journal: The Indian Medical Gazette #> year: '194' #> month: '5' #> url: https://web.archive.org/web/20200207182423/http://europepmc.org/backend/ptpmcrender.fcgi?accid=PMC5158424&blobtype=pdf #> start: 249-250 #> - type: article #> title: Serum Sickness-like Reactions #> authors: #> - family-names: Joseph Yerushalmi #> given-names: Sima Halevy #> name-suffix: Alex Zvulunov #> journal: Cutis #> year: '2002' #> volume: '69' #> month: '5' #> url: https://web.archive.org/web/20200321001112/http://www.gums.ac.ir/Upload/Modules/Contents/asset68/069050395.pdf #> start: 395-397 #> - type: article #> title: Emergencies in General Practice; Serum and Anaphylactic Reactions #> authors: #> - family-names: Williams #> given-names: D. A. #> journal: British Medical Journal #> year: '1952' #> volume: '1' #> issue: '4928' #> month: '6' #> issn: 0007-1447 #> url: https://www.bmj.com/content/1/4928/1469 #> start: 1469-1471 ```

Created on 2024-05-30 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os Ubuntu 20.04.6 LTS #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate C.UTF-8 #> ctype C.UTF-8 #> tz UTC #> date 2024-05-30 #> pandoc 3.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> backports 1.5.0 2024-05-23 [1] RSPM (R 4.3.0) #> bibtex 0.5.1 2023-01-26 [1] RSPM (R 4.3.0) #> cffr * 1.0.1 2024-04-09 [1] RSPM (R 4.3.0) #> cli 3.6.2 2023-12-11 [1] RSPM (R 4.3.0) #> curl 5.2.1 2024-03-01 [1] RSPM (R 4.3.0) #> desc 1.4.3 2023-12-10 [1] RSPM (R 4.3.0) #> digest 0.6.35 2024-03-11 [1] RSPM (R 4.3.0) #> evaluate 0.23 2023-11-01 [1] RSPM (R 4.3.0) #> fastmap 1.2.0 2024-05-15 [1] RSPM (R 4.3.0) #> fs 1.6.4 2024-04-25 [1] RSPM (R 4.3.0) #> glue 1.7.0 2024-01-09 [1] RSPM (R 4.3.0) #> htmltools 0.5.8.1 2024-04-04 [1] RSPM (R 4.3.0) #> jsonlite 1.8.8 2023-12-04 [1] RSPM (R 4.3.0) #> jsonvalidate 1.3.2 2021-11-03 [1] RSPM (R 4.3.0) #> knitr 1.46 2024-04-06 [1] RSPM (R 4.3.0) #> lifecycle 1.0.4 2023-11-07 [1] RSPM (R 4.3.0) #> magrittr 2.0.3 2022-03-30 [1] RSPM (R 4.3.0) #> purrr 1.0.2 2023-08-10 [1] RSPM (R 4.3.0) #> R.cache 0.16.0 2022-07-21 [1] RSPM (R 4.3.0) #> R.methodsS3 1.8.2 2022-06-13 [1] RSPM (R 4.3.0) #> R.oo 1.26.0 2024-01-24 [1] RSPM (R 4.3.0) #> R.utils 2.12.3 2023-11-18 [1] RSPM (R 4.3.0) #> R6 2.5.1 2021-08-19 [1] RSPM (R 4.3.0) #> Rcpp 1.0.12 2024-01-09 [1] RSPM (R 4.3.0) #> reprex 2.1.0 2024-01-11 [1] RSPM (R 4.3.0) #> rlang 1.1.3 2024-01-10 [1] RSPM (R 4.3.0) #> rmarkdown 2.27 2024-05-17 [1] RSPM (R 4.3.0) #> rstudioapi 0.16.0 2024-03-24 [1] RSPM (R 4.3.0) #> sessioninfo 1.2.2 2021-12-06 [1] RSPM (R 4.3.0) #> styler 1.10.3 2024-04-07 [1] RSPM (R 4.3.0) #> V8 4.4.2 2024-02-15 [1] RSPM (R 4.3.0) #> vctrs 0.6.5 2023-12-01 [1] RSPM (R 4.3.0) #> withr 3.0.0 2024-01-16 [1] RSPM (R 4.3.0) #> xfun 0.44 2024-05-15 [1] RSPM (R 4.3.0) #> yaml 2.3.8 2023-12-11 [1] RSPM (R 4.3.0) #> #> [1] /cloud/lib/x86_64-pc-linux-gnu-library/4.3 #> [2] /opt/R/4.3.3/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
iembry commented 4 months ago

Hi @dieghernan, thank you for your prompt response and for the alternative course of action.

I have modified the CITATION.cff file creation code with your suggestions and it worked perfectly!

Irucka