diff --git a/src/library/compiler/R/cmp.R b/src/library/compiler/R/cmp.R index 25fa516de9e..7ea069796f1 100644 --- a/src/library/compiler/R/cmp.R +++ b/src/library/compiler/R/cmp.R @@ -66,7 +66,7 @@ anyDots <- function(args) { is.ddsym <- function(name) { (is.symbol(name) || is.character(name)) && - length(grep("^\\.\\.[0-9]+$", as.character(name))) != 0 + any(grepl("^\\.\\.[0-9]+$", as.character(name))) } diff --git a/src/library/grDevices/R/device.R b/src/library/grDevices/R/device.R index 688a995d203..b705076f32c 100644 --- a/src/library/grDevices/R/device.R +++ b/src/library/grDevices/R/device.R @@ -335,10 +335,10 @@ checkIntFormat <- function(s) { ## OK if no unescaped %, so first remove those s <- gsub("%%", "", s, fixed=TRUE) - if(length(grep("%", s)) == 0L) return(TRUE) + if(!any(grepl("%", s, fixed=TRUE))) return(TRUE) ## now remove at most one valid(ish) integer format s <- sub("%[#0 ,+-]*[0-9.]*[diouxX]", "", s) - length(grep("%", s, fixed=TRUE)) == 0L + !any(grepl("%", s, fixed=TRUE)) } devAskNewPage <- function(ask=NULL) .External2(C_devAskNewPage, ask) diff --git a/src/library/grDevices/R/unix/x11.R b/src/library/grDevices/R/unix/x11.R index 37a829863a0..aba855bd535 100644 --- a/src/library/grDevices/R/unix/x11.R +++ b/src/library/grDevices/R/unix/x11.R @@ -129,7 +129,7 @@ checkX11Font <- function(font) if (!is.character(font)) X11FontError("must be a string") ## Check it has the right format - if (length(grep("(-[^-]+){14}", font)) > 0) { + if (any(grepl("(-[^-]+){14}", font))) { ## Force the %s and %d substitution formats into the right spots font <- sub("((-[^-]+){2})(-[^-]+){2}((-[^-]+){2})(-[^-]+)((-[^-]+){7})", "\\1-%s-%s\\4-%d\\7", font, perl = TRUE) diff --git a/src/library/grid/R/grob.R b/src/library/grid/R/grob.R index dcebe92ddd3..2c294dd250c 100644 --- a/src/library/grid/R/grob.R +++ b/src/library/grid/R/grob.R @@ -664,7 +664,7 @@ namePos <- function(pathName, names, grep) { partialPathMatch <- function(pathsofar, path, strict=FALSE, grep) { if (strict) { if (!any(grep)) - length(grep(paste0("^", pathsofar), path)) > 0L + any(grepl(paste0("^", pathsofar), path)) else { pathSoFarElts <- explode(pathsofar) pathElts <- explode(path) @@ -697,7 +697,7 @@ fullPathMatch <- function(pathsofar, gPath, strict, grep) { if (strict) match <- match(pathsofar, path, nomatch=0L) else - match <- (length(grep(paste0(path, "$"), pathsofar)) > 0L) + match <- any(grepl(paste0(path, "$"), pathsofar)) else { pathSoFarElts <- explode(pathsofar) pathElts <- explode(path) @@ -714,7 +714,7 @@ fullPathMatch <- function(pathsofar, gPath, strict, grep) { } while (match && index <= npe) { if (grep[index]) - match <- (length(grep(pathElts[index], pathSoFarElts[index])) > 0L) + match <- any(grepl(pathElts[index], pathSoFarElts[index])) else match <- match(pathSoFarElts[index], pathElts[index], nomatch = 0L) index <- index + 1 diff --git a/src/library/grid/R/ls.R b/src/library/grid/R/ls.R index 5fc37d81be0..7e261473430 100644 --- a/src/library/grid/R/ls.R +++ b/src/library/grid/R/ls.R @@ -732,7 +732,7 @@ pathListing <- function(x, gvpSep=" | ", gAlign=TRUE) { maxLen <- max(nchar(paths)) # Only if grob listings - if (sum(!vpListings) > 0) { + if (!all(vpListings)) { if (gAlign) { paths[!vpListings] <- padPrefix(paths[!vpListings], maxLen) } diff --git a/src/library/methods/R/RClassUtils.R b/src/library/methods/R/RClassUtils.R index 451c375da16..49ad00c1876 100644 --- a/src/library/methods/R/RClassUtils.R +++ b/src/library/methods/R/RClassUtils.R @@ -2412,7 +2412,7 @@ classesToAM <- function(classes, includeSubclasses = FALSE, maybe <- if(!is.null(f <- get0(x, where))) is.function(f) else FALSE if(maybe) maybe <- is(f, "genericFunction") || - (length(grep("UseMethod", deparse(f))) > 0) || + any(grepl("UseMethod", deparse(f))) || is.primitive(f) maybe } diff --git a/src/library/methods/R/trace.R b/src/library/methods/R/trace.R index 574da09d542..e7c21b5376f 100644 --- a/src/library/methods/R/trace.R +++ b/src/library/methods/R/trace.R @@ -283,7 +283,7 @@ .updateInImportsEnv(what, newFun, importingPkg) } } - if(length(grep("[^.]+[.][^.]+", what)) > 0) { #possible S3 method + if(any(grepl("[^.]+[.][^.]+", what))) { #possible S3 method ## check for a registered version of the object S3MTableName <- ".__S3MethodsTable__." if(!is.null(tbl <- get0(S3MTableName, envir = whereF, inherits = FALSE))) { @@ -815,8 +815,8 @@ insertSource <- function(source, package = "", } .mnames <- allMethodTables() if(length(methods) > 0) { - notThere <- vapply(methods, function(fname) - length(grep(fname, .mnames, fixed = TRUE)) == 0, NA) + notThere <- !vapply(methods, function(fname) + any(grepl(fname, .mnames, fixed = TRUE)), NA) if(any(notThere)) { warning(gettextf("cannot insert methods for these functions (methods table not found in source): %s", paste0('"', methods[notThere], '"', diff --git a/src/library/utils/R/completion.R b/src/library/utils/R/completion.R index c600a99e124..cd5b09dced0 100644 --- a/src/library/utils/R/completion.R +++ b/src/library/utils/R/completion.R @@ -733,15 +733,15 @@ inFunction <- ## note in passing whether we are the first argument (no '=' ## and no ',' in suffix) - if ((length(grep("=", suffix, fixed = TRUE)) == 0L) && - (length(grep(",", suffix, fixed = TRUE)) == 0L)) + if ((!any(grepl("=", suffix, fixed = TRUE))) && + (!any(grepl(",", suffix, fixed = TRUE)))) setIsFirstArg(TRUE) - if ((length(grep("=", suffix, fixed = TRUE))) && - (length(grep(",", substr(suffix, + if ((any(grepl("=", suffix, fixed = TRUE))) && + (!any(grepl(",", substr(suffix, tail.default(gregexpr("=", suffix, fixed = TRUE)[[1L]], 1L), - 1000000L), fixed = TRUE)) == 0L)) + 1000000L), fixed = TRUE)))) { ## we are on the wrong side of a = to be an argument, so ## we don't care even if we are inside a function diff --git a/src/library/utils/R/objects.R b/src/library/utils/R/objects.R index 2215fac0b7c..4d5cb51eb3f 100644 --- a/src/library/utils/R/objects.R +++ b/src/library/utils/R/objects.R @@ -608,7 +608,7 @@ function(x) if(tryCatch(!is.character(x), error = function(e) TRUE)) x <- as.character(substitute(x)) fs <- getAnywhere(x) - if (sum(!fs$dups) == 0L) + if (all(fs$dups)) return(NULL) if (sum(!fs$dups) > 1L) sapply(fs$objs[!fs$dups],