From a6a8d9f605da356242c179b01ac54751ce3ecf06 Mon Sep 17 00:00:00 2001 From: Thierry Onkelinx Date: Tue, 20 Aug 2024 16:49:09 +0200 Subject: [PATCH] author2df() handles character by converting it to person using as.person() --- NAMESPACE | 2 ++ R/store_authors.R | 13 +++++++++++-- man/author2df.Rd | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 68ffa202..85b037b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/R/store_authors.R b/R/store_authors.R index c42f5e0c..8c38ba77 100644 --- a/R/store_authors.R +++ b/R/store_authors.R @@ -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) { @@ -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)) } #' @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) ) data.frame( given = character(0), family = character(0), email = character(0), @@ -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)) +} + #' @export author2df.list <- function(person) { vapply( diff --git a/man/author2df.Rd b/man/author2df.Rd index 07fcd821..03075b08 100644 --- a/man/author2df.Rd +++ b/man/author2df.Rd @@ -7,7 +7,9 @@ author2df(person) } \arguments{ -\item{person}{The person object or a list of person objects, \code{NA} or \code{NULL}.} +\item{person}{The person object or a list of person objects, \code{NA} or \code{NULL}. +Any \code{"character"} is converted to a person object using \code{as.person()} with a +warning.} } \description{ Results in a data.frame with the given name, family name, e-mail, ORCID,