Skip to content

Commit

Permalink
Fix PlumeQuarto behavior with no-role authors (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou authored Aug 27, 2024
1 parent d0f8255 commit a46dcd5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 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)

* `PlumeQuarto` now properly handles authors with no roles (#81).

* `PlumeQuarto` now supports `.yml` and `.yaml` files (#82).

# plume 0.2.4
Expand Down
16 changes: 10 additions & 6 deletions R/plume-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ PlumeQuarto <- R6Class(
if (!private$has_col(col)) {
return()
}
out <- unnest_drop(private$plume, cols = all_of(col))
out <- summarise(
out,
`_` = list(tolower(.data[[col]])),
.by = all_of(private$id)
)
out <- unnest(private$plume, cols = all_of(col))
out <- summarise(out, `_` = if_not_na(
.data[[col]],
as_role_list(.data[[col]]),
all = TRUE
), .by = all_of(private$id))
out[["_"]]
},

Expand Down Expand Up @@ -243,6 +243,10 @@ PlumeQuarto <- R6Class(
)
)

as_role_list <- function(x) {
list(tolower(vec_drop_na(x)))
}

affiliation_keys <- c(
"number", "name", "department", "address", "city", "region", "state",
"country", "postal-code", "url", "isni", "ringgold", "ror"
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/_snaps/to-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,26 @@
given: Zip
family: Zap

# to_yaml() properly handles authors with no roles (#81)

Code
read_test_file(tmp_file)
Output
title: foo
author:
- id: aut1
name:
given: A
family: A
roles:
- formal analysis
- writing - original draft
- id: aut2
name:
given: B
family: B
roles: {}

# to_yaml() errors if no YAML headers is found

Code
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-to-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ test_that("to_yaml() can push data into YAML files", {
expect_snapshot(read_test_file(tmp_file))
})

test_that("to_yaml() properly handles authors with no roles (#81)", {
tmp_file <- withr::local_tempfile(
lines = "title: foo",
fileext = ".yaml"
)

aut <- PlumeQuarto$new(
data.frame(
given_name = c("A", "B"),
family_name = c("A", "B"),
writing = c(1, NA),
analysis = c(1, NA)
),
tmp_file
)
aut$to_yaml()

expect_snapshot(read_test_file(tmp_file))
})

# Errors ----

test_that("to_yaml() errors if no YAML headers is found", {
Expand Down

0 comments on commit a46dcd5

Please sign in to comment.