Skip to content

Commit

Permalink
s/sapply/vapply.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@84720 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
hornik committed Jul 21, 2023
1 parent 6f04756 commit c911c5f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/library/utils/R/citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ function(x,
if(style == "R") return(.format_person_as_R_code(x))

args <- c("given", "family", "email", "role", "comment")
include <- sapply(include, match.arg, args)
include <- vapply(include, match.arg, "", args)

## process defaults
braces <- braces[args]
Expand Down Expand Up @@ -482,7 +482,7 @@ function(x,
paste(do.call(c, rval), collapse = " ")
}

sapply(x, format_person1)
vapply(x, format_person1, "")
}

as.character.person <-
Expand All @@ -492,15 +492,15 @@ function(x, ...)
toBibtex.person <-
function(object, escape = FALSE, ...)
{
object <- sapply(object, function(p) {
object <- vapply(object, function(p) {
br <- if(is.null(p$family)) c("{", "}") else c("", "")
s <- format(p, include = c("family", "given"),
braces = list(given = br, family = c("", ",")))
if(isTRUE(escape) &&
(Encoding(s <- enc2utf8(s)) == "UTF-8"))
tools::encoded_text_to_latex(s, "UTF-8")
else s
})
}, "")
paste(object[nzchar(object)], collapse = " and ")
}

Expand Down Expand Up @@ -736,7 +736,7 @@ function(x, style = "text", .bibstyle = NULL,
else if(is.character(macros))
macros <- tools::loadRdMacros(macros,
tools:::initialRdMacros())
sapply(.bibentry_expand_crossrefs(x),
vapply(.bibentry_expand_crossrefs(x),
function(y) {
txt <- tools::toRd(y, style = .bibstyle)
## <FIXME>
Expand All @@ -757,7 +757,8 @@ function(x, style = "text", .bibstyle = NULL,
outputEncoding = "UTF-8", ...)
paste(readLines(out, encoding = "UTF-8"),
collapse = "\n")
})
},
"")
}

format_as_citation <- function(x, msg) { # also (.., bibtex)
Expand Down Expand Up @@ -1121,7 +1122,7 @@ function(..., recursive = FALSE)
toBibtex.bibentry <-
function(object, escape = FALSE, ...)
{
format_author <- function(author) paste(sapply(author, function(p) {
format_author <- function(author) paste(vapply(author, function(p) {
fnms <- p$family
only_given_or_family <-
(is.null(fnms) || is.null(p$given)) &&
Expand All @@ -1132,7 +1133,7 @@ function(object, escape = FALSE, ...)
gbrc <- if(only_given_or_family) c("{", "}") else ""
format(p, include = c("given", "family"),
braces = list(given = gbrc, family = fbrc))
}), collapse = " and ")
}, ""), collapse = " and ")

format_bibentry1 <- function(object) {
object <- unclass(object)[[1L]]
Expand All @@ -1143,8 +1144,10 @@ function(object, escape = FALSE, ...)
object$editor <- format_author(object$editor)

rval <- c(rval,
sapply(names(object), function (n)
paste0(" ", n, " = {", object[[n]], "},")),
vapply(names(object),
function (n)
paste0(" ", n, " = {", object[[n]], "},"),
""),
"}", "")
if(isTRUE(escape)) {
rval <- enc2utf8(rval)
Expand Down Expand Up @@ -1535,7 +1538,7 @@ function(x)
x <- .read_authors_at_R_field(x)
header <- attr(x, "header")
footer <- attr(x, "footer")
x <- sapply(x, .format_person_for_plain_author_spec)
x <- vapply(x, .format_person_for_plain_author_spec, "")
## Drop persons with irrelevant roles.
x <- x[nzchar(x)]
## And format.
Expand Down Expand Up @@ -1622,7 +1625,7 @@ local({
}

authorList <- function(paper)
sapply(paper$author, shortName)
vapply(paper$author, shortName, "")

if (!missing(previous))
cited <<- previous
Expand Down

0 comments on commit c911c5f

Please sign in to comment.