R/utils.R

Defines functions .format_output .coerce_matrix_build .integerize_subset

.integerize_subset <- function(index, subset) {
    if (is.null(subset)) {
        subset
    } else if (!is.numeric(subset)) {
        dummy <- seq_len(generic_num_obs(index@ptr))
        names(dummy) <- index@names
        dummy[subset]
    } else if (!is.integer(subset)) {
        as.integer(subset)
    } else {
        subset
    }
}

.coerce_matrix_build <- function(X, transposed) {
    if (!is.matrix(X)) {
        X <- as.matrix(X)
    }    

    if (!transposed) {
        X <- t(X)
    }

    if (!is.double(X)) {
        storage.mode(X) <- "double"
    }

    X
}

.format_output <- function(output, name, to.get) {
    if (isFALSE(to.get)) {
        output[[name]] <- NULL
    } else if (identical(to.get, "transposed")) {
        ; # no-op
    } else if (isTRUE(to.get) || identical(to.get, "normal")) {
        if (is.matrix(output[[name]])) {
            output[[name]] <- t(output[[name]])
        }
    } else {
        stop("unsupported option '", to.get, "'")
    }
    output
}
LTLA/BiocNeighbors documentation built on Dec. 12, 2024, 7:45 a.m.