Skip to content

Commit

Permalink
Add sep parameter in get_contributions() (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou committed Dec 9, 2023
1 parent 833b01c commit a449a22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# plume (development version)

* `$get_contributions()` gains a new parameter `sep` that allows for finer control of how to separate contributors or roles (#49).

* `$to_yaml()` now throws an error when invalid ORCID identifiers are found.

* `Plume`'s parameter `by` is now working properly (#48).
Expand Down
3 changes: 3 additions & 0 deletions R/plume.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Plume <- R6Class(
#' @param literal_names Should literal names be used?
#' @param divider Separator used to separate roles and authors. Uses `": "`
#' by default.
#' @param sep Separator used to separate roles or authors.
#' @param sep_last Separator used to separate the last two roles or authors
#' if more than one item is associated to a role or author.
#' @return A character vector.
Expand All @@ -239,6 +240,7 @@ Plume <- R6Class(
dotted_initials = TRUE,
literal_names = FALSE,
divider = ": ",
sep = ", ",
sep_last = " and "
) {
role <- private$pick("role")
Expand All @@ -261,6 +263,7 @@ Plume <- R6Class(
}
out <- summarise(out, !!pars$var := enumerate(
contribution_items(pars, by_author, alphabetical_order),
sep = sep,
last = sep_last
), .by = all_of(pars$grp_var))
if (are_credit_roles(private$roles) || private$crt) {
Expand Down
3 changes: 3 additions & 0 deletions man/Plume.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/test-get-contributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ test_that("get_contributions() return authors' contributions", {
aut$get_contributions(by_author = FALSE, alphabetical_order = TRUE),
c("a: P.-P.P., R.R. and Z.Z.", "b: Z.Z.")
)
expect_equal(
aut$get_contributions(by_author = FALSE, sep = "; "),
c("a: Z.Z.; R.R. and P.-P.P.", "b: Z.Z.")
)
expect_equal(
aut$get_contributions(by_author = FALSE, sep_last = " & "),
c("a: Z.Z., R.R. & P.-P.P.", "b: Z.Z.")
Expand Down

0 comments on commit a449a22

Please sign in to comment.