1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
### ============================================================================
### colTabulates
###
### ----------------------------------------------------------------------------
### Non-exported methods
###
.DelayedMatrix_block_colTabulates <- function(x, rows = NULL, cols = NULL,
values = NULL, ..., useNames = TRUE) {
# Check input type
stopifnot(is(x, "DelayedMatrix"))
DelayedArray:::.get_ans_type(x, must.be.numeric = FALSE)
# Subset
x <- ..subset(x, rows, cols)
# Compute result
if (is.null(values)) {
# NOTE: Need to compute values from entire x (not block-by-block)
values <- sort(
unique(
unlist(colblock_APPLY(x = x,
FUN = function(x) {
unique(as.vector(x))
}),
use.names = FALSE)),
na.last = TRUE)
}
val <- colblock_APPLY(x = x,
FUN = colTabulates,
values = values,
...,
useNames = useNames)
if (length(val) == 0L) {
return(matrix(0L,0,0))
}
val <- do.call(rbind, val)
if (!useNames) {
val <- unname(val)
}
val
}
### ----------------------------------------------------------------------------
### Exported methods
###
# ------------------------------------------------------------------------------
# General method
#
#' @inherit MatrixGenerics::colTabulates
#' @importFrom DelayedArray type
#' @importMethodsFrom DelayedArray seed
#' @rdname colTabulates
#' @template common_params
#' @template lowercase_x
#' @export
#' @template example_dm_S4VectorsDF
#' @author Peter Hickey
#' @examples
#'
#' colTabulates(dm_DF)
setMethod("colTabulates", "DelayedMatrix",
function(x, rows = NULL, cols = NULL, values = NULL,
force_block_processing = FALSE, ..., useNames = TRUE) {
if (!type(x) %in% c("integer", "logical", "raw")) {
stop("Argument 'x' is not of type integer, logical, or raw",
" (type = ", type(x), ")")
}
.smart_seed_dispatcher(x, generic = MatrixGenerics::colTabulates,
blockfun = .DelayedMatrix_block_colTabulates,
force_block_processing = force_block_processing,
rows = rows,
cols = cols,
values = values,
...,
useNames = useNames)
}
)
|