Skip to content

[Bugzilla#18865] Use any(.) over sum(.) > 0 #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library/compiler/R/cmp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}


Expand Down
4 changes: 2 additions & 2 deletions src/library/grDevices/R/device.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/library/grDevices/R/unix/x11.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/library/grid/R/grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/library/grid/R/ls.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/methods/R/RClassUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
any(grepl("UseMethod", deparse(f))) ||
any(grepl("UseMethod", deparse(f), fixed = TRUE)) ||

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! Agree it's an improvement. I don't have an easy workflow for updating patches, so I'll just make a note of it in the issue tracker.

is.primitive(f)
maybe
}
Expand Down
6 changes: 3 additions & 3 deletions src/library/methods/R/trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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], '"',
Expand Down
10 changes: 5 additions & 5 deletions src/library/utils/R/completion.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/library/utils/R/objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down