R/utils.R

Defines functions isMatrixLike chunkRanges

chunkRanges <- function(a, n, i = NULL) {
    if (n > a) {
        stop(paste("Cannot split", a, "into", n, "chunks. Reduce the number of chunks."))
    }
    k <- as.integer(a / n)
    r <- as.integer(a %% n)
    range <- function(i, k, r) {
        c((i - 1L) * k + min(i - 1L, r) + 1L, i * k + min(i, r))
    }
    if (!is.null(i)) {
        range(i, k, r)
    } else {
        sapply(seq_len(n), range, k, r)
    }
}

# Incomplete check if x is matrix-like. Should check for length as well.
isMatrixLike <- function(x) {
    length(dim(x)) == 2L
}

Try the LinkedMatrix package in your browser

Any scripts or data that you put into this service are public.

LinkedMatrix documentation built on July 8, 2020, 5:53 p.m.