diff --git a/R/bootstrapCompartments.R b/R/bootstrapCompartments.R index 07f14a30..02cf3cc7 100644 --- a/R/bootstrapCompartments.R +++ b/R/bootstrapCompartments.R @@ -63,7 +63,7 @@ bootstrapCompartments <- function( # bootstrap and recompute compartments BiocParallel::bpprogressbar(BPPARAM) <- FALSE resamp.compartments <- bplapply( - 1:ncol(bmeans), + seq_len(ncol(bmeans)), function(b) { # get the shrunken bins with new global mean boot.mean <- as.matrix(bmeans[, b]) @@ -80,7 +80,7 @@ bootstrapCompartments <- function( cor.bins <- getCorMatrix(s.bins, squeeze = !group) # Stupid check for perfect correlation with global mean - if (any(is.na(cor.bins$binmat.cor))) { + if (anyNA(cor.bins$binmat.cor)) { absig <- matrix(rep(NA, nrow(cor.bins$binmat.cor))) } else { absig <- getABSignal(cor.bins, assay = assay) diff --git a/R/condenseRE.R b/R/condenseRE.R index 5e1b77b8..bfc5456a 100644 --- a/R/condenseRE.R +++ b/R/condenseRE.R @@ -19,7 +19,7 @@ condenseRE <- function(obj) { # it will build a list of SummarizedExperiments with relevant information # from computing compartments if (!is(obj, "RaggedExperiment")) stop("Input needs to be a RaggedExperiment") - se_list <- lapply(1:length(assayNames(obj)), function(a) { + se_list <- lapply(seq_along(assayNames(obj)), function(a) { compactSummarizedExperiment(obj, i = a) }) @@ -64,11 +64,11 @@ condenseSE <- function(obj, sample.name = NULL) { # check and see how many samples we are extracting if (length(sample.name) == 1) { - obj.dense <- lapply(1:length(obj), .condenseGR, obj = obj, sample = sample.name) + obj.dense <- lapply(seq_along(obj), .condenseGR, obj = obj, sample = sample.name) return(Reduce("merge", obj.dense)) } else { obj.dense.lst <- lapply(sample.name, function(s) { - obj.dense <- lapply(1:length(obj), .condenseGR, obj = obj, sample = s) + obj.dense <- lapply(seq_along(obj), .condenseGR, obj = obj, sample = s) return(Reduce("merge", obj.dense)) }) names(obj.dense.lst) <- sample.name diff --git a/R/getBinMatrix.R b/R/getBinMatrix.R index e16be4e0..99adbce1 100644 --- a/R/getBinMatrix.R +++ b/R/getBinMatrix.R @@ -56,7 +56,7 @@ getBinMatrix <- function( genome = c("hg19", "hg38", "mm9", "mm10") ) { - if (any(is.na(mat))){ + if (anyNA(mat)){ stop("Matrix must not contain NAs") } if (nrow(mat) != length(genloc)){ diff --git a/R/getCompartments.R b/R/getCompartments.R index a2d8af1d..0038be2d 100644 --- a/R/getCompartments.R +++ b/R/getCompartments.R @@ -38,9 +38,9 @@ getCompartments <- function( } boot_msg <- "" - if (bootstrap & boot.parallel) { + if (bootstrap && boot.parallel) { boot_msg <- sprintf("Bootstrapping in parallel with %d cores", bpnworkers(bpparams[[2]])) - } else if (bootstrap & !boot.parallel & group) { + } else if (bootstrap && !boot.parallel && group) { boot_msg <- "Not bootstrapping in parallel could take a long time..." } @@ -153,7 +153,7 @@ getCompartments <- function( obj.cor <- getCorMatrix(obj.bins, squeeze = !group) - if (any(is.na(obj.cor$binmat.cor))) { + if (anyNA(obj.cor$binmat.cor)) { obj.cor$gr$pc <- matrix(rep(NA, nrow(obj.cor$binmat.cor))) obj.svd <- obj.cor$gr } else { diff --git a/R/getDomainInflections.R b/R/getDomainInflections.R index 0e91971b..01dad342 100644 --- a/R/getDomainInflections.R +++ b/R/getDomainInflections.R @@ -51,7 +51,7 @@ getDomainInflections <- function( end(tiles) <- suppressWarnings(end(tiles) - 1) # add a column for continuous runs! - mcols(tiles)$run <- seq(1:length(tiles)) + mcols(tiles)$run <- seq(seq_along(tiles)) mcols(tiles)$score <- NA # overlap @@ -83,7 +83,7 @@ getDomainInflections <- function( } # loop through the non-contiguous space - grl <- lapply(1:length(non_contig), function(i) { + grl <- lapply(seq_along(non_contig), function(i) { message("Block processing non-contiguous space for block ", i) # get block of contiguous sequence if (non_contig[i] == non_contig[1]) { @@ -132,7 +132,7 @@ getDomainInflections <- function( # subset the original granges # gr.inflect <- gr[gr.signs.diff,] - if (length(gr.signs) == 2 & any(gr.signs.bool)) { + if (length(gr.signs) == 2 && any(gr.signs.bool)) { gr.inflect <- gr[2, ] # special case gr.inflect.new <- GRanges( seqnames = seqnames(gr.inflect), diff --git a/R/getShrinkageTargets.R b/R/getShrinkageTargets.R index becde8e4..b3d6ce50 100644 --- a/R/getShrinkageTargets.R +++ b/R/getShrinkageTargets.R @@ -23,7 +23,7 @@ getShrinkageTargets <- function(obj, group) { msg <- paste( "Error while subsetting targets: provided column", column.type, "not found:" ) - if (no_colnames & group.is_colnames) { + if (no_colnames && group.is_colnames) { message("The provided object does not have any column names - use column indices instead.") } message(msg) diff --git a/R/imputeKNN.R b/R/imputeKNN.R index 3c9740bd..2267008f 100644 --- a/R/imputeKNN.R +++ b/R/imputeKNN.R @@ -35,7 +35,7 @@ imputeKNN <- function( assay <- match.arg(assay) # stop early if there aren't any NAs to impute - if (!any(is.na(assay(obj)))) { + if (!anyNA(assay(obj))) { message("No NAs found. Nothing to impute.") return(obj) } diff --git a/R/meanSmoother.R b/R/meanSmoother.R index f645d2c5..ec68b9fb 100644 --- a/R/meanSmoother.R +++ b/R/meanSmoother.R @@ -32,7 +32,7 @@ meanSmoother <- function(mat, k = 1, iters = 2, delta = 0, weights = NULL) { eps <- delta + 1 weights <- weights %||% rep(1, length(mat)) - while (pos < iters & eps > delta) { + while (pos < iters && eps > delta) { mat0 <- mat pos <- pos + 1 mat <- .meanSmoother.internal(mat0, weights = weights, k = k) diff --git a/R/parallel.R b/R/parallel.R index 154c129d..1d44aa67 100644 --- a/R/parallel.R +++ b/R/parallel.R @@ -2,7 +2,7 @@ #' inference and bootstrapping #' @keywords internal check_optim <- function(workers, group, chr_count, bootstrap) { - if (group & chr_count < workers[1]) { + if (group && chr_count < workers[1]) { flog.info( "Grouped inference with more outer workers than chromosomes leaves %d of %d workers unused", workers[1] - chr_count, @@ -12,7 +12,7 @@ check_optim <- function(workers, group, chr_count, bootstrap) { flog.info("Consider using a single core for the outer worker and more cores for the inner bootstrap worker") } } - if (!group & bootstrap & workers[1] < workers[2]) { + if (!group && bootstrap && workers[1] < workers[2]) { flog.info("More outer (column-wise) than inner (bootstrap) workers is faster for single-cell inference") } } @@ -29,7 +29,7 @@ check_worker_count <- function(bpparam, group, chr_count, bootstrap, avail_worke avail_msg <- sprintf("but your system has only %d cores", avail_workers) info_msg <- "See parallelly::availableCores(which = 'all') for more information on available resources" - if (workers[1] == 1 | workers[2] == 1) { + if (workers[1] == 1 || workers[2] == 1) { msg <- sprintf( "Requested %d %s workers %s\n%s", max(workers), @@ -105,7 +105,7 @@ verify_workers <- function(n_workers) { get_nested_params <- function(BPPARAM, boot.parallel) { stopifnot("Only two BiocParallelParam objects can be used" = length(BPPARAM) <= 2) single_param <- length(BPPARAM) == 1 - BPPARAM <- if (single_param & is.list(BPPARAM)) BPPARAM[[1]] else BPPARAM + BPPARAM <- if (single_param && is.list(BPPARAM)) BPPARAM[[1]] else BPPARAM if (boot.parallel) { if (single_param) { diff --git a/R/preprocessArrays.R b/R/preprocessArrays.R index 1d3694c9..73a77253 100644 --- a/R/preprocessArrays.R +++ b/R/preprocessArrays.R @@ -45,7 +45,7 @@ preprocessArrays <- function( } # impute missing values if possible - if (any(is.na(minfi::getBeta(obj.opensea)))) { + if (anyNA(minfi::getBeta(obj.opensea))) { flog.debug("Imputing missing values.") obj.opensea <- imputeKNN(obj.opensea, assay = "array") } diff --git a/R/transformTFIDF.R b/R/transformTFIDF.R index 4f642da7..2e750ad1 100644 --- a/R/transformTFIDF.R +++ b/R/transformTFIDF.R @@ -23,7 +23,7 @@ #' #' @export transformTFIDF <- function(mat, scale.factor = 1e5, binarize = FALSE) { - if (!is(mat, "matrix") & !is(mat, "Matrix")) { + if (!is(mat, "matrix") && !is(mat, "Matrix")) { stop("Input needs to be a matrix.") } diff --git a/R/utils.R b/R/utils.R index 0f1d840a..6d5153dd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -62,7 +62,7 @@ flogit <- function(p, sqz = 0.000001) { #' #' @export fexpit <- function(x, sqz = 0.000001) { - midpt <- .5 + midpt <- 0.5 squoze <- exp(x) / (1 + exp(x)) inflate <- 1 / (1 - (sqz * midpt)) ((squoze - midpt) * inflate) + midpt @@ -285,7 +285,7 @@ importBigWig <- function( } # it is now a GRanges object - if (any(is.na(seqlengths(bw.raw)))) stop("Imported bigwig does not have seqlengths") + if (anyNA(seqlengths(bw.raw))) stop("Imported bigwig does not have seqlengths") species <- switch( genome,