Skip to content

Commit

Permalink
Only use given name initials if the script allows it (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou committed Jan 29, 2024
1 parent 6a6e3da commit d565a1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 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)

* `$new(initials_given_name = TRUE)` no longer makes initials if names are written in a script that doesn't use letter cases (#73).

* Fixed `PlumeQuarto`'s example no longer working with `withr` 3.0.0 due to a wrong usage of `local_tempfile()` (#70).

* `$get_author_list()` now throws a more informative error if corresponding authors have not been set (#69).
Expand Down
8 changes: 6 additions & 2 deletions R/plume-handler.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ PlumeHandler <- R6Class(
},

add_author_names = function() {
if (private$initials_given_name) {
if (private$initials_given_name && private$has_uppercase("given_name")) {
private$make_initials("given_name", dot = TRUE)
}
private$add_literal_names()
if (any(has_uppercase(private$get("literal_name")))) {
if (private$has_uppercase("literal_name")) {
private$add_initials()
}
},
Expand Down Expand Up @@ -193,6 +193,10 @@ PlumeHandler <- R6Class(
private$has_col(var) && col_count(private$plume, var) > 1L
},

has_uppercase = function(var) {
any(has_uppercase(private$get(var)))
},

has_col = function(col) {
if (any(has_metachr(col))) {
col <- regex(col)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-initialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ test_that("`initials_given_name = TRUE` initialises given names", {
)
})

test_that("`initials_given_name` doesn't make initials in scripts not using letter cases (#73)", {
aut <- Plume$new(
data.frame(given_name = "菖蒲", family_name = "佐藤"),
initials_given_name = TRUE
)
expect_equal(aut$get_plume()$given_name, "菖蒲")
})

test_that("`family_name_first = TRUE` switches given and family name", {
aut <- Plume$new(basic_df, family_name_first = TRUE)
expect_equal(
Expand Down

0 comments on commit d565a1e

Please sign in to comment.