Skip to content

Commit

Permalink
Implement a bullet handler in check_col() (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou committed Jan 22, 2024
1 parent 6ae6fb4 commit 67d86d5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 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_author_list()` now throws a more informative error if corresponding authors have not been set (#69).

* The `.roles` parameter in `set_main_contributors()` now always applies roles that are not already set to unnamed expressions. This allows you to set the same main contributors across all but a few specific roles in a single call (#65).

* `$to_yaml()` now only adds the `affiliations` schema if there is at least one affiliation (#67).
Expand Down
7 changes: 7 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
)
)

.col_bullets <- list(
corresponding = c(
i = "Did you forget to assign corresponding authors?",
i = "Use `set_corresponding_authors()` to set corresponding authors."
)
)

.links <- list(
crt = c("Contributor Roles Taxonomy", "https://credit.niso.org"),
quarto_schemas = c(
Expand Down
7 changes: 5 additions & 2 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ search_ <- function(x, callback, n = 1) {
if (!is.null(n)) {
failed <- failed[n]
}
nms <- if (is_named(failed)) names(failed) else failed
set_names(x[failed], nms)
out <- x[failed]
if (is_named(x)) {
return(out)
}
set_names(out, failed)
}

without_indexed_error <- function(expr, ...) {
Expand Down
3 changes: 2 additions & 1 deletion R/plume-handler.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ PlumeHandler <- R6Class(
if (is.null(missing_col)) {
return()
}
bullets <- .col_bullets[[names(missing_col)]]
msg <- glue("Column `{missing_col}` doesn't exist.")
abort_check(msg = msg, ...)
abort_check(msg = msg, bullets = bullets, ...)
},

check_authors = function() {
Expand Down
7 changes: 2 additions & 5 deletions R/plume.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ Plume <- R6Class(
check_args("bool", list(email, phone, fax, url))
check_string(sep, allow_empty = FALSE)
vars <- private$pick("corresponding", "literal_name", squash = FALSE)
private$check_col(vars$corresponding, bullets = c(
i = "Did you forget to assign corresponding authors?",
i = "Use `set_corresponding_authors()` to set corresponding authors."
))
private$check_col(vars["corresponding"])
arg_names <- get_params_set_to_true()
if (is_empty(arg_names)) {
return()
Expand Down Expand Up @@ -282,8 +279,8 @@ Plume <- R6Class(
check_suffix_format(format, param = "suffix")
key_set <- als_key_set(format)
vars <- private$pick(key_set, squash = FALSE)
private$check_col(vars)
cols <- squash(vars)
private$check_col(cols)
out <- unnest(private$plume, cols = all_of(cols))
out <- add_group_ids(out, vars)
symbols <- list_assign(private$symbols, orcid = private$orcid_icon)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/get-author-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<error/rlang_error>
Error:
! Column `corresponding` doesn't exist.
i Did you forget to assign corresponding authors?
i Use `set_corresponding_authors()` to set corresponding authors.
Code
(expect_error(aut$get_author_list("o")))
Output
Expand Down

0 comments on commit 67d86d5

Please sign in to comment.