paleolimbot / rbbt

R Interface to the Better BiBTex Zotero Connector
142 stars 25 forks source link

Suggestion: long json file #14

Closed florisvdh closed 3 years ago

florisvdh commented 3 years ago

I'm not sure how easy or sensible it is to implement the following. I suppose the json format comes from BBT @retorquere.

To me it seems more interesting to have a long-formatted json file created (like the yaml alternative), for reasons of readability and because this will invoke smaller diffs in git when specific fields have been changed in Zotero items (provided that the order of records is not changed when overwriting). Or would performance be affected by this approach?

Currently it shows (one line, soft-wrapped) as:

{"id":"incollection-a3e3","abstract":"An abstract","author":[{"family":"InCollection","given":"Author"},{"family":"Second","given":"Author"},{"family":"Third","given":"Author"}],"collection-number":"23","collection-title":"A <span class=\"nocase\">Series in Title Case</span>","container-title":"The book without editor title","DOI":"10.1007/s11284-012-0928-6","edition":"3","editor":[{"family":"Collection","given":"Editor"},{"family":"Second","given":"Editor"},{"family":"Third","given":"Editor"}],"event-place":"Somewhere over the rainbow","ISBN":"123-456-7890","issued":{"date-parts":[[2020,12]]},"page":"12-34","publisher":"Title Case and ALLCAPS","publisher-place":"Somewhere over the rainbow","section":"9","title":"A double author part title","type":"chapter","URL":"https://www.inbo.be"}

Compared with the same record in a json file produced with RStudio's 'insert citation' from its visual markdown editor (however, this feature cannot be used in the plain Rmd mode):

    {
        "id": "incollection-a3e3",
        "DOI": "10.1007/s11284-012-0928-6",
        "ISBN": "123-456-7890",
        "URL": "https://www.inbo.be",
        "author": [
            {
                "family": "InCollection",
                "given": "Author"
            },
            {
                "family": "Second",
                "given": "Author"
            },
            {
                "family": "Third",
                "given": "Author"
            }
        ],
        "collection-number": "23",
        "collection-title": "A <span class=\"nocase\">Series in Title Case</span>",
        "container-title": "The book without editor title",
        "edition": "3",
        "editor": [
            {
                "family": "Collection",
                "given": "Editor"
            },
            {
                "family": "Second",
                "given": "Editor"
            },
            {
                "family": "Third",
                "given": "Editor"
            }
        ],
        "issued": {
            "date-parts": [
                [
                    2020,
                    12
                ]
            ]
        },
        "note": "Citation Key: incollection-a3e3 Section: 9 tex.owner: me tex.timestamp: 2019-08-20",
        "page": "12-34",
        "publisher": "Title Case and ALLCAPS",
        "publisher-place": "Somewhere over the rainbow",
        "title": "A double author part title",
        "type": "chapter"
    }
paleolimbot commented 3 years ago

I think you can use jsonlite::prettify() for this:

rbbt::bbt_bib("dunnington_etal18", translator = "csljson", .action = jsonlite::prettify)
#> [
#>     {
#>         "id": "dunnington_etal18",
#>         "abstract": "Separating the timing and effects of multiple watershed disturbances is critical to a comprehensive understanding of lakes, which is required to effectively manage lacustrine systems that may be experiencing adverse water quality changes. Advances in X-ray fluorescence (XRF) technology has led to the availability of high-resolution, high-quality bulk geochemical data for aquatic sediments, which in combination with carbon, nitrogen, δ13C, and δ15N have the potential to identify watershed-scale disturbance in lake sediment cores. We integrated documented anthropogenic disturbances and changes in bulk geochemical parameters at 8 lakes within the Halifax Regional Municipality (HRM), Nova Scotia, Canada, 6 of which serve as drinking water sources. These data reflect more than 2 centuries of anthropogenic disturbance in the HRM that included deforestation, urbanization and related development, and water-level change. Deforestation activity was documented at Lake Major and Pockwock Lake by large increases in Ti, Zr, K, and Rb (50–300%), and moderate increases in C/N (>10%). Urbanization was resolved at Lake Fletcher, Lake Lemont, and First Lake by increases in Ti, Zr, K, and Rb (10–300%), decreases in C/N (>10%), and increases in δ15N (>2.0‰). These data broadly agree with previous paleolimnological bioproxy data, in some cases identifying disturbances that were not previously identified. Collectively these data suggest that bulk geochemical parameters and lake sediment archives are a useful method for lake managers to identify causal mechanisms for possible water quality changes resulting from watershed-scale disturbance.",
#>         "author": [
#>             {
#>                 "family": "Dunnington",
#>                 "given": "Dewey W."
#>             },
#>             {
#>                 "family": "Spooner",
#>                 "given": "I. S."
#>             },
#>             {
#>                 "family": "Krkošek",
#>                 "given": "Wendy H."
#>             },
#>             {
#>                 "family": "Gagnon",
#>                 "given": "Graham A."
#>             },
#>             {
#>                 "family": "Cornett",
#>                 "given": "R. Jack"
#>             },
#>             {
#>                 "family": "White",
#>                 "given": "Chris E."
#>             },
#>             {
#>                 "family": "Misiuk",
#>                 "given": "Benjamin"
#>             },
#>             {
#>                 "family": "Tymstra",
#>                 "given": "Drake"
#>             }
#>         ],
#>         "container-title": "Lake and Reservoir Management",
#>         "DOI": "10.1080/10402381.2018.1461715",
#>         "issue": "4",
#>         "issued": {
#>             "date-parts": [
#>                 [
#>                     2018,
#>                     6,
#>                     18
#>                 ]
#>             ]
#>         },
#>         "page": "334-348",
#>         "title": "Anthropogenic activity in the Halifax region, Nova Scotia, Canada, as recorded by bulk geochemistry of lake sediments",
#>         "type": "article-journal",
#>         "URL": "https://www.tandfonline.com/doi/full/10.1080/10402381.2018.1461715",
#>         "volume": "34"
#>     }
#> ]
#> 

Created on 2020-09-04 by the reprex package (v0.3.0)

florisvdh commented 3 years ago

Thanks for the suggestion, didn't know that. Maybe the .action argument could be exposed in bbt_write_bib() as well?

paleolimbot commented 3 years ago

Sorry this took me a bit! You should be good to go with filter = jsonlite::pretify in bbt_write_bib()