Skip to content

Commit

Permalink
author2df() returns the role of the person
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Aug 20, 2024
1 parent f3cd48e commit 4cb0cb4
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 12 deletions.
23 changes: 12 additions & 11 deletions R/store_authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ store_authors <- function(x = ".") {
this_desc$get_authors() |>
author2df() |>
cbind(usage = 1) |>
rbind(current) -> new_author_df
rbind(cbind(current, role = "")) -> new_author_df
} else {
citation_meta$new(x)$get_meta$authors |>
cbind(usage = 1, email = "") -> cit_meta
Expand All @@ -35,7 +35,13 @@ store_authors <- function(x = ".") {
}

#' Convert person object in a data.frame.
#'
#' Results in a data.frame with the given name, family name, e-mail, ORCID,
#' affiliation and role.
#' Missing elements result in an empty string (`""`).
#' Persons with multiple roles will have the roles as a comma separated string.
#' @param person The person object or a list of person objects, `NA` or `NULL`.
#' @family utils
#' @export
author2df <- function(person) {
UseMethod("author2df", person)
Expand All @@ -53,15 +59,15 @@ author2df.logical <- function(person) {
)
data.frame(
given = character(0), family = character(0), email = character(0),
orcid = character(0), affiliation = character(0)
orcid = character(0), affiliation = character(0), role = character(0)

Check warning on line 62 in R/store_authors.R

View check run for this annotation

Codecov / codecov/patch

R/store_authors.R#L60-L62

Added lines #L60 - L62 were not covered by tests
)
}

#' @export
author2df.NULL <- function(person) {
data.frame(
given = character(0), family = character(0), email = character(0),
orcid = character(0), affiliation = character(0)
orcid = character(0), affiliation = character(0), role = character(0)

Check warning on line 70 in R/store_authors.R

View check run for this annotation

Codecov / codecov/patch

R/store_authors.R#L68-L70

Added lines #L68 - L70 were not covered by tests
)
}

Expand Down Expand Up @@ -93,23 +99,18 @@ author2df.person <- function(person) {
do.call(what = rbind)
)
}
if (all(person$role %in% c("cph", "fnd"))) {
return(data.frame(
given = character(0), family = character(0), email = character(0),
orcid = character(0), affiliation = character(0)
))
}

data.frame(
given = person$given, family = person$family,
given = coalesce(person$given, ""), family = coalesce(person$family, ""),
email = coalesce(person$email, ""),
orcid = ifelse(
has_name(person$comment, "ORCID"), unname(person$comment["ORCID"]), ""
),
affiliation = ifelse(
has_name(person$comment, "affiliation"),
unname(person$comment["affiliation"]), ""
)
),
role = paste(person$role, collapse = ", ")
)
}

Expand Down
1 change: 1 addition & 0 deletions man/ask_yes_no.Rd

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

25 changes: 24 additions & 1 deletion man/author2df.Rd

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

1 change: 1 addition & 0 deletions man/bookdown_zenodo.Rd

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

1 change: 1 addition & 0 deletions man/c_sort.Rd

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

1 change: 1 addition & 0 deletions man/clean_git.Rd

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

1 change: 1 addition & 0 deletions man/create_hexsticker.Rd

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

1 change: 1 addition & 0 deletions man/defunct.Rd

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

1 change: 1 addition & 0 deletions man/execshell.Rd

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

1 change: 1 addition & 0 deletions man/is_repository.Rd

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

1 change: 1 addition & 0 deletions man/is_workdir_clean.Rd

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

1 change: 1 addition & 0 deletions man/menu_first.Rd

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

1 change: 1 addition & 0 deletions man/new_branch.Rd

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

1 change: 1 addition & 0 deletions man/store_authors.Rd

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

1 change: 1 addition & 0 deletions man/use_author.Rd

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

1 change: 1 addition & 0 deletions man/validate_email.Rd

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

1 change: 1 addition & 0 deletions man/validate_orcid.Rd

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

1 change: 1 addition & 0 deletions man/yesno.Rd

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

0 comments on commit 4cb0cb4

Please sign in to comment.