Skip to content

Commit bce5e25

Browse files
author
hornik
committed
s/sapply/vapply.
git-svn-id: https://svn.r-project.org/R/trunk@88290 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 1b530fa commit bce5e25

File tree

13 files changed

+45
-38
lines changed

13 files changed

+45
-38
lines changed

src/library/base/R/datetime.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,12 @@ Math.POSIXt <- function (x, ...)
534534

535535
.check_tzones <- function(...)
536536
{
537-
tzs <- unique(sapply(list(...), function(x) {
538-
y <- attr(x, "tzone")
539-
if(is.null(y)) "" else y[1L]
540-
}))
537+
tzs <- unique(vapply(list(...),
538+
function(x) {
539+
y <- attr(x, "tzone")
540+
if(is.null(y)) "" else y[1L]
541+
},
542+
""))
541543
tzs <- tzs[nzchar(tzs)]
542544
if(length(tzs) > 1L)
543545
warning("'tzone' attributes are inconsistent")

src/library/base/R/grep.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@ function(x, m, invert = FALSE, value)
564564
value <- rep_len(value, np)
565565
}
566566
y <- y[pos]
567-
x[pos] <- paste0(sapply(y, `[`, 1L), value, sapply(y, `[`, 2L))
567+
x[pos] <- paste0(vapply(y, `[`, "", 1L),
568+
value,
569+
vapply(y, `[`, "", 2L))
568570
return(x)
569571
}
570572

src/library/grDevices/R/unix/quartz.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ quartzFonts <- function(...) {
122122
fontNames <- names(fonts)
123123
nnames <- length(fontNames)
124124
if (nnames == 0L) {
125-
if (!all(sapply(fonts, is.character)))
125+
if (!all(vapply(fonts, is.character, NA)))
126126
stop("invalid arguments in 'quartzFonts' (must be font names)")
127127
else
128128
get(".Quartz.Fonts", envir=.Quartzenv)[unlist(fonts)]

src/library/grDevices/R/unix/x11.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ X11Fonts <- function(...)
173173
fontNames <- names(fonts)
174174
nnames <- length(fontNames)
175175
if (nnames == 0) {
176-
if (!all(sapply(fonts, is.character)))
176+
if (!all(vapply(fonts, is.character, NA)))
177177
stop("invalid arguments in 'X11Fonts' (must be font names)")
178178
else
179179
get(".X11.Fonts", envir=.X11env)[unlist(fonts)]

src/library/grDevices/R/windows/windows.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ print.SavedPlots <- function(x, ...)
218218
}
219219
cat("Saved Plots from R version 1.4.0 or later\n\n")
220220
cat(" Contains", x[[2L]], "out of a maximum", x[[3L]], "plots\n")
221-
lens <- sapply(x[[5L]], length)[1L:x[[2L]]]
221+
lens <- lengths(x[[5L]])[1L:x[[2L]]]
222222
cat(" #plot calls are", paste(lens, collapse=", "), "\n")
223223
cat(" Current position is plot", 1L + x[[4L]], "\n")
224224
invisible(x)
@@ -283,7 +283,7 @@ windowsFonts <- function(...)
283283
fontNames <- names(fonts)
284284
nnames <- length(fontNames)
285285
if (nnames == 0) {
286-
if (!all(sapply(fonts, is.character)))
286+
if (!all(vapply(fonts, is.character, NA)))
287287
stop("invalid arguments in 'windowsFonts' (must be font names)")
288288
else
289289
get(".Windows.Fonts", envir=.WindowsEnv)[unlist(fonts)]

src/library/tools/R/citation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function(file, encoding = "ASCII")
135135
out <- Filter(Negate(is.null), out)
136136
## If we found nothing return nothing ...
137137
if(!length(out)) return(NULL)
138-
entries <- sapply(out, `[[`, 1L)
138+
entries <- vapply(out, `[[`, "", 1L)
139139
fields <- lapply(out, `[[`, 2L)
140140
out <- data.frame(File = file,
141141
Entry = entries,

src/library/tools/R/encodings.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function(file = NULL)
4949
MIME <- sapply(mapply(c, out$Name, out$Aliases),
5050
function(u) {
5151
if(any(ind <- grep("preferred MIME name", u)))
52-
sapply(strsplit(u[ind], " +"), `[[`, 1L)
52+
vapply(strsplit(u[ind], " +"), `[[`, "", 1L)
5353
else
5454
character()
5555
})

src/library/tools/R/news.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ function(file)
204204
ire <- sprintf("^[[:space:]]*([%s])[[:space:]]+", sep)
205205
ind <- grepl(ire, lines)
206206
list(entries =
207-
sapply(split(lines, cumsum(ind)),
207+
vapply(split(lines, cumsum(ind)),
208208
function(s)
209-
sub(ire, "", .collapse(sub("^\t?", "", s)))
210-
),
209+
sub(ire, "", .collapse(sub("^\t?", "", s))),
210+
""),
211211
header = header,
212212
chunk = chunk,
213213
date = date)
@@ -577,7 +577,7 @@ function(file)
577577
function(x)
578578
{
579579
get_section_names <- function(x)
580-
sapply(x, function(e) .Rd_get_text(e[[1L]]))
580+
vapply(x, function(e) .Rd_get_text(e[[1L]]), "")
581581

582582
get_item_texts <- function(x) {
583583
## Currently, chunks should consist of a single \itemize list

src/library/tools/R/packages.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function(files, type, fields, verbose, validate = FALSE)
168168
## files was without path at this point in original code,
169169
## use filetbs instead to compute pkg names and set db names
170170
filetbs <- basename(files)
171-
packages <- sapply(strsplit(filetbs, "_", fixed = TRUE), `[`, 1L)
171+
packages <- vapply(strsplit(filetbs, "_", fixed = TRUE), `[`, "", 1L)
172172
db <- vector(length(files), mode = "list")
173173
names(db) <- filetbs #files was not full paths before
174174
## Many (roughly length(files)) warnings are *expected*, hence

src/library/tools/R/recode.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ encoded_text_to_latex <-
5252
paste(y, collapse="")
5353
}
5454
as.vector(switch(encoding,
55-
"latin1" = sapply(x, do_latin1),
56-
"latin2" = sapply(x, do_latin2),
57-
"latin9" = sapply(x, do_latin9),
58-
"UTF-8" = sapply(x, do_utf8),
59-
"utf8" = sapply(x, do_utf8),
55+
"latin1" = vapply(x, do_latin1, ""),
56+
"latin2" = vapply(x, do_latin2, ""),
57+
"latin9" = vapply(x, do_latin9, ""),
58+
"UTF-8" = vapply(x, do_utf8, ""),
59+
"utf8" = vapply(x, do_utf8, ""),
6060
stop("unimplemented encoding")
6161
))
6262
}

0 commit comments

Comments
 (0)