Skip to content

Commit

Permalink
Fix adding long author fields
Browse files Browse the repository at this point in the history
E.g. comments are often long.

Closes #91.
  • Loading branch information
gaborcsardi committed Mar 5, 2021
1 parent fab566f commit 6be1338
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# Development version

* Adding authors with long names or other fields (`comment`, typically)
works well now (#91).

* `get_deps()` now removes unneeded whitespace from version requirements
(#84).

Expand Down
2 changes: 1 addition & 1 deletion R/authors-at-r.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ deparse_author_at_r <- function(x1) {
x1 <- x1[! vapply(x1, is.null, TRUE)]
paste0(
c("person(", rep(" ", length(x1) - 1)),
names(x1), " = ", vapply(x1, fixed_deparse, ""),
names(x1), " = ", vapply(x1, fixed_deparse1, ""),
c(rep(",", length(x1) - 1), ")")
)
}
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ parse_full_name <- function(x) {
# keep everything in UTF-8. Apparently, if you mark the input string
# as native, then it will not have a chance to do any conversion.

fixed_deparse <- function(x, ...) {
fixed_deparse1 <- function(x, ...) {
# Need to do this, because console and code input might be in
# the native encoding
x <- enc2utf8(x)
Encoding(x) <- "unknown"
out <- deparse(x, ...)
out <- paste(deparse(x, width.cutoff = 500L, ...), collapse = " ")
Encoding(out) <- "UTF-8"
out
}
39 changes: 39 additions & 0 deletions tests/testthat/test-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,42 @@ test_that("normalization keeps authors in UTF-8", {
"UTF-8"
)
})

test_that("long comments are deparsed properly", {
authors <- c(
person(
given = "First",
family = "Last",
role = c("aut", "cre"),
email = "flast@email.org",
comment = c(
ORCID = "0000-0000-0000-0000",
affiliation = "University One"
)
),
person(
given = "Second",
family = "Last",
role = "aut",
email = "slast@email.org",
comment = c(
ORCID = "0000-0000-0000-0000",
affiliation = c("University One", "University Two")
)
)
)

desc <- desc::description$new("!new")
desc$set_authors(authors)

expect_equal(
desc$get_authors()[[1]]$comment,
authors[[1]]$comment
)
expect_equal(
desc$get_authors()[[2]]$comment,
authors[[2]]$comment
)

expect_equal(
})

0 comments on commit 6be1338

Please sign in to comment.