Skip to content

Commit

Permalink
author2df() handles character by converting it to person using as.per…
Browse files Browse the repository at this point in the history
…son()
  • Loading branch information
ThierryO committed Aug 20, 2024
1 parent 4cb0cb4 commit a6a8d9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(author2df,"NULL")
S3method(author2df,character)
S3method(author2df,default)
S3method(author2df,list)
S3method(author2df,logical)
Expand Down Expand Up @@ -156,6 +157,7 @@ importFrom(tools,RdTextFilter)
importFrom(tools,loadPkgRdMacros)
importFrom(tools,loadRdMacros)
importFrom(tools,toTitleCase)
importFrom(utils,as.person)
importFrom(utils,askYesNo)
importFrom(utils,browseURL)
importFrom(utils,data)
Expand Down
13 changes: 11 additions & 2 deletions R/store_authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ store_authors <- function(x = ".") {
#' 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`.
#' Any `"character"` is converted to a person object using `as.person()` with a
#' warning.
#' @family utils
#' @export
author2df <- function(person) {
Expand All @@ -49,13 +51,13 @@ author2df <- function(person) {

#' @export
author2df.default <- function(person) {
stop("author2df() is not implemented for ", class(person))
stop("`author2df()` is not implemented for ", class(person))

Check warning on line 54 in R/store_authors.R

View check run for this annotation

Codecov / codecov/patch

R/store_authors.R#L54

Added line #L54 was not covered by tests
}

#' @export
author2df.logical <- function(person) {
stopifnot(
"author2df() is not implemented for `TRUE` or `FALSE`" = is.na(person)
"`author2df()` is not implemented for `TRUE` or `FALSE`" = is.na(person)

Check warning on line 60 in R/store_authors.R

View check run for this annotation

Codecov / codecov/patch

R/store_authors.R#L59-L60

Added lines #L59 - L60 were not covered by tests
)
data.frame(
given = character(0), family = character(0), email = character(0),
Expand All @@ -71,6 +73,13 @@ author2df.NULL <- function(person) {
)
}

#' @export
#' @importFrom utils as.person
author2df.character <- function(person) {
warning("`author2df()` converted a character to a person using `as.person()`")
author2df(as.person(person))

Check warning on line 80 in R/store_authors.R

View check run for this annotation

Codecov / codecov/patch

R/store_authors.R#L79-L80

Added lines #L79 - L80 were not covered by tests
}

#' @export
author2df.list <- function(person) {
vapply(
Expand Down
4 changes: 3 additions & 1 deletion man/author2df.Rd

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

0 comments on commit a6a8d9f

Please sign in to comment.