R/UTILS-as-methods.R

Defines functions as.data.frame.pairdist as.data.frame.crossdist as.matrix.pairdist as.matrix.crossdist

# ==================================================================================================
# Coercion methods for cross/pair-dist
# ==================================================================================================

#' as.matrix
#'
#' \pkg{proxy} exported a non-generic `as.matrix` function. This is to re-export the base version
#' and add coercion methods for `pairdist` and `crossdist`.
#'
#' @name as.matrix
#' @export
#'
#' @param x,... See [base::as.matrix()].
#'
#' @seealso [base::as.matrix()]
#'
setGeneric("as.matrix", package = "base")

#' @method as.matrix crossdist
#' @export
#'
as.matrix.crossdist <- function(x, ...) {
    x <- cbind(x)
    class(x) <- c("matrix", "array")
    x
}

#' @method as.matrix pairdist
#' @export
#'
as.matrix.pairdist <- function(x, ...) {
    x <- cbind(x)
    class(x) <- c("matrix", "array")
    x
}

#' @method as.data.frame crossdist
#' @export
#'
as.data.frame.crossdist <- function(x, ...) {
    as.data.frame(as.matrix(x, ...), ...)
}

#' @method as.data.frame pairdist
#' @export
#'
as.data.frame.pairdist <- function(x, ...) {
    as.data.frame(as.matrix(x, ...), ...)
}

Try the dtwclust package in your browser

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

dtwclust documentation built on Sept. 11, 2024, 9:07 p.m.