Code Monkey home page Code Monkey logo

plume's Introduction

plume

CRAN status R-CMD-check Codecov test coverage

Overview

plume provides tools for handling and generating author-related information for scientific writing in R Markdown and Quarto. The package implements two R6 classes:

  • PlumeQuarto: class that allows you to push author metadata in the YAML header of Quarto files. The generated YAML complies with Quarto’s author and affiliations schemas. This is the class to use if you work with journal templates.

  • Plume: class that generates author lists and other author-related information as character strings. This is an easy and convenient solution when you don’t need preformatted documents.

Installation

Install plume from CRAN with:

install.packages("plume")

Alternatively, you can install the development version of plume from GitHub with:

# install.packages("pak")
pak::pak("arnaudgallou/plume")

Usage

The minimal required data to work with plume classes is a data set containing given and family names but you would normally want to provide more information such as email addresses, ORCIDs, affiliations, etc.

library(plume)

encyclopedists
#> # A tibble: 4 × 10
#>   given_name     family_name        email  phone orcid supervision writing note 
#>   <chr>          <chr>              <chr>  <chr> <chr>       <dbl>   <dbl> <chr>
#> 1 Denis          Diderot            dider… +1234 0000…           1       1 born…
#> 2 Jean-Jacques   Rousseau           rouss… <NA>  0000…          NA       1 <NA> 
#> 3 François-Marie Arouet             aroue… <NA>  <NA>           NA       1 also…
#> 4 Jean           Le Rond d'Alembert alemb… <NA>  0000…           1       1 born…
#> # ℹ 2 more variables: affiliation_1 <chr>, affiliation_2 <chr>

Plume$new(encyclopedists)
#> # A tibble: 4 × 11
#>      id given_name     family_name literal_name initials email phone orcid note 
#>   <int> <chr>          <chr>       <chr>        <chr>    <chr> <chr> <chr> <chr>
#> 1     1 Denis          Diderot     Denis Dider… DD       dide… +1234 0000… born…
#> 2     2 Jean-Jacques   Rousseau    Jean-Jacque… J-JR     rous… <NA>  0000… <NA> 
#> 3     3 François-Marie Arouet      François-Ma… F-MA     arou… <NA>  <NA>  also…
#> 4     4 Jean           Le Rond d'… Jean Le Ron… JLRd'A   alem… <NA>  0000… born…
#> # ℹ 2 more variables: affiliation <list>, role <list>

PlumeQuarto lets you push author metadata in the YAML header of any .qmd file using the to_yaml() method.

Consider the following example:

---
title: Encyclopédie
---

Qui scribit bis legit
aut <- PlumeQuarto$new(
  encyclopedists,
  file = "file.qmd"
)
aut$set_corresponding_authors(1, 4)
aut$to_yaml()
---
title: Encyclopédie
author:
  - id: aut1
    name:
      given: Denis
      family: Diderot
    email: [email protected]
    phone: '+1234'
    orcid: 0000-0000-0000-0001
    note: born in 1713 in Langres
    attributes:
      corresponding: true
    roles:
      - supervision
      - writing - original draft
    affiliations:
      - ref: aff1
  - id: aut2
    name:
      given: Jean-Jacques
      family: Rousseau
    email: [email protected]
    orcid: 0000-0000-0000-0002
    attributes:
      corresponding: false
    roles:
      - writing - original draft
    affiliations:
      - ref: aff2
  - id: aut3
    name:
      given: François-Marie
      family: Arouet
    email: [email protected]
    note: also known as Voltaire
    attributes:
      corresponding: false
    roles:
      - writing - original draft
    affiliations:
      - ref: aff2
  - id: aut4
    name:
      given: Jean
      family: Le Rond d'Alembert
    email: [email protected]
    orcid: 0000-0000-0000-0003
    note: born in 1717 in Paris
    attributes:
      corresponding: true
    roles:
      - supervision
      - writing - original draft
    affiliations:
      - ref: aff1
      - ref: aff3
affiliations:
  - id: aff1
    name: Université de Paris
  - id: aff2
    name: Lycée Louis-le-Grand
  - id: aff3
    name: Collège des Quatre-Nations
---

Qui scribit bis legit

Alternatively, you can generate author information as character strings using Plume:

aut <- Plume$new(encyclopedists)
aut$set_corresponding_authors(diderot, .by = "family_name")

aut$get_author_list(suffix = "^a,^cn")
#> Denis Diderot^1,^\*†
#> Jean-Jacques Rousseau^2^
#> François-Marie Arouet^2^‡
#> Jean Le Rond d'Alembert^1,3^§

aut$get_contact_details()
#> [email protected] (Denis Diderot)

aut$get_affiliations()
#> ^1^Université de Paris
#> ^2^Lycée Louis-le-Grand
#> ^3^Collège des Quatre-Nations

aut$get_notes()
#> ^†^born in 1713 in Langres
#> ^‡^also known as Voltaire
#> ^§^born in 1717 in Paris

aut$get_contributions()
#> Supervision: D.D. and J.L.R.d'A.
#> Writing - original draft: D.D., J.-J.R., F.-M.A. and J.L.R.d'A.

aut2 <- Plume$new(
  encyclopedists,
  roles = c(
    supervision = "supervised the project",
    writing = "contributed to the Encyclopédie"
  ),
  symbols = list(affiliation = letters)
)

aut2$get_author_list("^a^")
#> Denis Diderot^a^
#> Jean-Jacques Rousseau^b^
#> François-Marie Arouet^b^
#> Jean Le Rond d'Alembert^a,c^

aut2$get_contributions(roles_first = FALSE, divider = " ")
#> D.D. and J.L.R.d'A. supervised the project
#> D.D., J.-J.R., F.-M.A. and J.L.R.d'A. contributed to the Encyclopédie

Acknowledgements

Thanks to:

plume's People

Contributors

arnaudgallou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

pherephobia

plume's Issues

`$to_yaml()` drops line breaks preceding leading/isolated `---`

tmp <- withr::local_tempfile(
  lines = "---\n---\nLorem ipsum\n---",
  fileext = ".qmd"
)

cat(readr::read_file(tmp))
#> ---
#> ---
#> Lorem ipsum
#> ---

aut <- PlumeQuarto$new(
  tibble::tibble(given_name = "Zip", family_name = "Zap"),
  tmp
)
aut$to_yaml()

cat(readr::read_file(tmp))
#> ---
#> author:
#>   - id: aut1
#>     name:
#>       given: Zip
#>       family: Zap
#> affiliations: {}
#> ---
#> Lorem ipsum---

Release plume 0.1.0

First release:

Prepare for release:

  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • git push

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

Assigning multiple main contributors to a single role via `...` doesn't work

aut <- Plume$new(encyclopedists)
aut$set_main_contributors(writing = c(3, 4))
aut$get_plume() |> 
  dplyr::select(id, role) |> 
  tidyr::unnest(role)
#> # A tibble: 8 × 3
#>      id role                     contributor_rank
#>   <int> <chr>                               <int>
#> 1     1 Supervision                            NA
#> 2     1 Writing - original draft               NA
#> 3     2 <NA>                                   NA
#> 4     2 Writing - original draft               NA
#> 5     3 <NA>                                   NA
#> 6     3 Writing - original draft               NA
#> 7     4 Supervision                            NA
#> 8     4 Writing - original draft               NA

This is because the method will name each vector element dynamically in this case.

Consider differentiating authors with the same initials using multiple characters from family names

Currently, initials are made using the first character of each name. Considering two authors named Zip Zap and Zap Zop, the initials will be the same (Z.Z.) in the contribution list.

In such a case, it's recommended to use $get_contributions(literal_names = TRUE) to avoid any confusion.

I could also implement a way to distinguish the initials of authors using multiple characters from family names when the use of literal names is not an option. E.g., Zip Zap and Zap Zop could be initialised as Z.Za. and Z.Zo..

`$get_contributions(alphabetical_order = TRUE)` doesn't reorder authors only

aut <- Plume$new(tibble::tibble(
  given_name = c("Zip", "Pim"),
  family_name = c("Zap", "Pam"),
  role_1 = c("z", NA),
  role_2 = c("a", "a")
))
aut$get_contributions(roles_first = FALSE, by_author = TRUE, alphabetical_order = FALSE)
#> Z.Z.: z and a
#> P.P.: a
aut$get_contributions(roles_first = FALSE, by_author = TRUE, alphabetical_order = TRUE)
#> Z.Z.: a and z
#> P.P.: a

aut$get_contributions(roles_first = TRUE, by_author = FALSE, alphabetical_order = FALSE)
#> z: Z.Z.
#> a: Z.Z. and P.P.
aut$get_contributions(roles_first = TRUE, by_author = FALSE, alphabetical_order = TRUE)
#> a: P.P. and Z.Z.
#> z: Z.Z.

Release plume 0.2.0

Prepare for release:

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • devtools::submit_cran()
  • Approve email
  • Accepted 🎉

Finish up:

  • usethis::use_github_release()
  • usethis::use_dev_version()

Example broken by withr 3.0.0

See r-lib/withr#256. withr::local_tempfile() may not have been working as you intended, and definitely no longer works under {withr} 3.0.0 (when executed in certain ways):

plume/man/PlumeQuarto.Rd

Lines 14 to 17 in 67d86d5

tmp_file <- withr::local_tempfile(
lines = "---\ntitle: Encyclopédie\n---",
fileext = ".qmd"
)

I confirmed this by running:

devtools::check_examples(document = FALSE)

The linked issue cites a few ways to proceed, you can choose which is most appealing to you.

Release plume 0.2.2

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

readme & encyclopedists using old style of author contributions

The example on the readme, and plume::encyclopedists is using the old style of author contribution.

Is it possible to allow numbers other than 1 in the role to allow for ranking the contributions?

Is it possible to internationalise the role names (visualisation vs. visualization), and allow ad hoc contributions?

Release plume 0.2.4

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)

Add support to the YAML key `roles`

Quarto handles author contributions via the roles key that wasn't documented before. See the new front matter page.

I should implement that feature in PlumeQuarto. This implies the following:

  • The only remaining useful methods inherited from Plume relate to setting author's status.
  • These methods could then be put in a parent class that both Plume and PlumeQuarto inherit.
  • The job of Plume and PlumeQuarto is now more distinct.
  • The only job of PlumeQuarto is now to push author data into YAML headers.
  • plm_push() is no longer needed and can be removed.

Release plume 0.2.3

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

Release plume 0.2.1

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

`get_contributions()` reorders contributors when using CRediT roles and `by_author = TRUE`

while the original author order should be preserved.

aut <- Plume$new(encyclopedists)
aut$get_contributions(roles_first = FALSE, by_author = TRUE)
#> D.D.: Supervision and Writing - original draft
#> J.L.R.d'A.: Supervision and Writing - original draft
#> J.-J.R.: Writing - original draft
#> F.-M.A.: Writing - original draft

Compare to:

aut <- Plume$new(
  encyclopedists,
  roles = c(supervision = "supervision", writing = "writing")
)
aut$get_contributions(roles_first = FALSE, by_author = TRUE)
#> D.D.: supervision and writing
#> J.-J.R.: writing
#> F.-M.A.: writing
#> J.L.R.d'A.: supervision and writing

Make the `.roles` parameter of `set_main_contributors()` work with a combination of named and unnamed expressions

Currently, the only ways to set the same main contributors across all but a few roles is to specify main contributors for each roles, or to call set_main_contributors() twice, once to set main contributors across all roles and another time to define main contributors more specifically. E.g.:

aut <- Plume$new(tibble::tibble(
  given_name = LETTERS[1:3],
  family_name = LETTERS[1:3],
  analysis = 1,
  writing = 1,
  methodology = 1,
))
aut$set_main_contributors(3, .roles = aut$get_roles())
aut$set_main_contributors(writing = 2)
aut$get_contributions()
#> Formal analysis: C.C., A.A. and B.B.
#> Methodology: C.C., A.A. and B.B.
#> Writing - original draft: B.B., A.A. and C.C.

I could combine these features so that .roles only applies to unnamed expressions while named expressions would work as normal:

# set the third author as main contributor to all roles but writing
aut$set_main_contributors(3, writing = 2, .roles = aut$get_roles())

`$get_contributions()` doesn't handle namesakes

aut <- Plume$new(tibble::tibble(
  given_name = c("Zip", "Zip"),
  family_name = c("Zap", "Zap"),
  role_1 = c("a", NA),
  role_2 = c("b", "b")
))
aut$get_contributions(roles_first = FALSE, by_author = TRUE)
#> Z.Z.: a, b and b

Generalise CRediT roles handling system to custom roles

Currently, the only way to use custom roles is to pass roles as character strings for every contributor which is error prone and not very flexible.

A better way would be to pass roles via a (named) vector. Contributors would be assigned roles using the same data structure as for CRediT roles.

data
#> # A tibble: 2 × 4
#>   given_name family_name analysis writing
#>   <chr>      <chr>          <dbl>   <dbl>
#> 1 Zip        Zap                1       1
#> 2 Ric        Rac               NA       1

Plume$new(
  data,
  roles = c(
    analysis = "performed the analyses",
    writing = "wrote the manuscript"
  )
)

Keys in the vector identify column names while values are the actual roles to be used.

`$to_yaml()` can slightly modify YAML data not related to authors

Rewriting YAML headers slightly alter some data unrelated to authors:

lines <- "
  foo: !!float 123
  # a comment that will be dropped
  bar: >
    Lorem ipsum
    Vivamus quis
  baz: &id1
    a: 1
    b: 2
  boz: *id1
"

yaml::yaml.load(lines) |> 
  yaml::as.yaml() |> 
  cat()
#> foo: 123.0
#> bar: |
#>   Lorem ipsum Vivamus quis
#> baz:
#>   a: 1
#>   b: 2
#> boz:
#>   a: 1
#>   b: 2

This might not be desirable… I could detect these cases, write author data in an empty YAML header at the beginning of the document if they exist, and notify the user about it.

Standard role columns can take multiple roles

Currently, it's possible to pass multiple roles to one column:

Plume$new(tibble::tibble(
  given_name = c("Zip", "Ric"),
  family_name = c("Zap", "Rac"),
  role = c("a", "b"),
))

This will cause issues when assigning the degrees of contribution (#14) and shouldn't be allowed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.