Skip to content

Commit 06393c5

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

File tree

30 files changed

+57
-48
lines changed

30 files changed

+57
-48
lines changed

src/library/base/R/character.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ abbreviate <-
6262
if(method == "both.sides")
6363
## string reversion: FIXME reverse .Internal(abbreviate(.))
6464
chRev <- function(x)
65-
sapply(lapply(strsplit(x, NULL), rev), paste, collapse="")
65+
vapply(lapply(strsplit(x, NULL), rev),
66+
paste, "", collapse = "")
6667
dup2 <- rep.int(TRUE, length(names.arg))
6768
these <- names.arg
6869
repeat {

src/library/base/R/datetime.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ function(..., recursive = FALSE)
922922
}
923923
args <- list(...)
924924
if(!length(args)) return(.difftime(double(), "secs"))
925-
ind <- sapply(args, inherits, "difftime")
925+
ind <- vapply(args, inherits, NA, "difftime")
926926
pos <- which(!ind)
927927
units <- sapply(args[ind], attr, "units")
928928
if(all(units == (un1 <- units[1L]))) {

src/library/base/R/dump.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dump <- function (list, file = "dumpdata.R", append = FALSE,
2222
{
2323
if(is.character(file)) {
2424
## avoid opening a file if there is nothing to dump
25-
ex <- sapply(list, exists, envir=envir)
25+
ex <- vapply(list, exists, NA, envir = envir)
2626
if(!any(ex)) return(invisible(character()))
2727
if(nzchar(file)) {
2828
file <- file(file, if(append) "a" else "w")

src/library/base/R/kronecker.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ kronecker <- function (X, Y, FUN = "*", make.dimnames = FALSE, ...)
5252
dnx <- vector("list", length(dX))
5353
else if (ld < 0L)
5454
dnx <- c(dnx, vector("list", -ld))
55-
tmp <- which(sapply(dnx, is.null))
55+
tmp <- which(vapply(dnx, is.null, NA))
5656
dnx[tmp] <- lapply(tmp, function(i) rep.int("", dX[i]))
5757

5858
if (is.null(dny))
5959
dny <- vector("list", length(dY))
6060
else if (ld > 0)
6161
dny <- c(dny, vector("list", ld))
62-
tmp <- which(sapply(dny, is.null))
62+
tmp <- which(vapply(dny, is.null, NA))
6363
dny[tmp] <- lapply(tmp, function(i) rep.int("", dY[i]))
6464

6565
k <- length(dim(opobj))

src/library/base/R/namespace.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ namespaceImportFrom <- function(self, ns, vars, generics, packages,
10561056
## and is in order of adding.
10571057
current <- getNamespaceInfo(self, "imports")
10581058
poss <- lapply(rev(current), `[`, n)
1059-
poss <- poss[!sapply(poss, is.na)]
1059+
poss <- poss[!vapply(poss, is.na, NA)]
10601060
if(length(poss) >= 1L) {
10611061
prev <- names(poss)[1L]
10621062
warning(sprintf(gettext("replacing previous import %s by %s when loading %s"),

src/library/base/R/summary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ summary.data.frame <-
164164
tmp <- rbind(tmp, matrix("", nr - nrow(sms), ncol(sms)))
165165
sms <- apply(tmp, 1L, function(x) paste(x, collapse=" "))
166166
## produce a suitable colname: undoing padding
167-
wid <- sapply(tmp[1L, ], nchar, type="w") # might be NA
167+
wid <- vapply(tmp[1L, ], nchar, 0, type = "w") # might be NA
168168
blanks <- paste(character(max(wid)), collapse = " ")
169169
wcn <- ncw(cn)
170170
pad0 <- floor((wid - wcn)/2)

src/library/grDevices/R/glyph.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ glyphFontList <- function(...) {
168168
fonts <- list(...)
169169
if (!length(fonts))
170170
stop("List must include at least one font")
171-
if (!all(sapply(fonts, function(x) inherits(x, "RGlyphFont"))))
171+
if (!all(vapply(fonts, inherits, NA, "RGlyphFont")))
172172
stop("Invalid glyph font")
173173
class(fonts) <- "RGlyphFontList"
174174
fonts

src/library/grDevices/R/postscript.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ postscriptFonts <- function(...)
524524
fontNames <- names(fonts)
525525
nnames <- length(fontNames)
526526
if (nnames == 0L) {
527-
if (!all(sapply(fonts, is.character)))
527+
if (!all(vapply(fonts, is.character, NA)))
528528
stop(gettextf("invalid arguments in '%s' (must be font names)",
529529
"postscriptFonts"), domain = NA)
530530
else
@@ -578,7 +578,7 @@ pdfFonts <- function(...)
578578
fontNames <- names(fonts)
579579
nnames <- length(fontNames)
580580
if (nnames == 0L) {
581-
if (!all(sapply(fonts, is.character)))
581+
if (!all(vapply(fonts, is.character, NA)))
582582
stop(gettextf("invalid arguments in '%s' (must be font names)",
583583
"pdfFonts"), domain = NA)
584584
else
@@ -1009,7 +1009,7 @@ embedGlyphs <- function(file, glyphInfo, outfile = file,
10091009
infoList <- FALSE
10101010
if (!inherits(glyphInfo, "RGlyphInfo")) {
10111011
if (is.list(glyphInfo)) {
1012-
if (!all(sapply(glyphInfo, inherits, "RGlyphInfo"))) {
1012+
if (!all(vapply(glyphInfo, inherits, NA, "RGlyphInfo"))) {
10131013
stop("Invalid 'glyphInfo'")
10141014
} else {
10151015
infoList <- TRUE

src/library/graphics/R/fourfoldplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function(x, color = c("#99CCFF", "#6699CC"), conf.level = 0.95,
6565
dnx <- dimnames(x)
6666
if(is.null(dnx))
6767
dnx <- vector("list", 3L)
68-
for(i in which(sapply(dnx, is.null)))
68+
for(i in which(vapply(dnx, is.null, NA)))
6969
dnx[[i]] <- LETTERS[seq_len(dim(x)[i])]
7070
if(is.null(names(dnx)))
7171
i <- 1L : 3L

src/library/graphics/R/plot.design.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ plot.design <-
3030
stop("'y' must be a numeric vector")
3131
if(!is.data.frame(x)) # or allow factor (see 2 lines below)?? {FIXME}
3232
stop("'x' must be a data frame")
33-
if(!all(sapply(x, is.factor)) && !is.factor(x)) # incl "ordered"
33+
if(!all(vapply(x, is.factor, NA)) && !is.factor(x)) # incl "ordered"
3434
stop("all columns/components of 'x' must be factors")
3535
k <- ncol(x)
3636
if(anyNA(y)) {
@@ -75,17 +75,17 @@ plot.design <-
7575
x <- stats::model.frame(y , data = x)
7676
}
7777
else if(is.numeric(y)) {
78-
x <- cbind(y,x[,sapply(x, is.factor)])
78+
x <- cbind(y, x[, vapply(x, is.factor, NA)])
7979
tmpname <- match.call()
8080
names(x) <- as.character(c(tmpname[[3L]],names(x[,-1])))
8181
}
8282
else if(is.character(y)) {
8383
ynames <- y
8484
y <- data.frame(x[,y])
85-
if(sum(sapply(y, is.numeric)) != ncol(y)) {
85+
if(sum(vapply(y, is.numeric, NA)) != ncol(y)) {
8686
stop("a variable in 'y' is not numeric")
8787
}
88-
x <- x[,sapply(x, is.factor)]
88+
x <- x[, vapply(x, is.factor, NA)]
8989
xnames <- names(x)
9090
x <- cbind(x,y)
9191
names(x) <- c(xnames,ynames)
@@ -98,8 +98,8 @@ plot.design <-
9898
x <- stats::model.frame(x)
9999
}
100100

101-
i.fac <- sapply(x, is.factor)
102-
i.num <- sapply(x, is.numeric)
101+
i.fac <- vapply(x, is.factor, NA)
102+
i.num <- vapply(x, is.numeric, NA)
103103
nResp <- sum(i.num)
104104
if (nResp == 0)
105105
stop("there must be at least one numeric variable!")

0 commit comments

Comments
 (0)