R/check_input.R

Defines functions check_input.tbl check_input.data.frame check_input.xts check_input.matrix check_input.numeric check_input.default check_input

Documented in check_input check_input.data.frame check_input.default check_input.matrix check_input.numeric check_input.tbl check_input.xts

#' Internal Functions to check the consistency of input arguments.
#'
#' @param x A vector, a matrix, a xts or a tibble object.
#'
#' @return A matrix object.
#' @export
#'
#' @examples
#' #
check_input <- function(x) {
  UseMethod("check_input", x)
}

#' @rdname check_input
#' @export
check_input.default <- function(x) {
  rlang::abort("CMA doesn't support the `", class(x), "` yet.")
}

#' @rdname check_input
#' @export
check_input.numeric <- function(x) {
  as.matrix(x)
}

#' @rdname check_input
#' @export
check_input.matrix <- function(x) {
  x
}

#' @rdname check_input
#' @export
check_input.xts <- function(x) {
  as.matrix(x)
}

#' @rdname check_input
#' @export
check_input.data.frame <- function(x) {
  as.matrix(dplyr::select(x, where(is.numeric)))
}

#' @rdname check_input
#' @export
check_input.tbl <- function(x) {
  as.matrix(dplyr::select(x, where(is.numeric)))
}
Reckziegel/CMA documentation built on July 13, 2022, 10:31 p.m.