R/check_variables.R

Defines functions check_variables

Documented in check_variables

#' Checks validity of variables' matrix
#'
#' Checks whether the matrix is numeric,
#' has expected number of columns (\code{ncol}),
#' and has no missing/infinite data.
#'
#'
#' @param var Matrix N x ncol
#' @param var_label Variable label for error messages
#' @return Logical TRUE, if none of the tests fail
#' @keywords internal
#' @export
#'
#' @examples
#' check_variables(matrix(c(1, 2, 3, 4), ncol=2), "test matrix")
check_variables <- function(var, var_label){
  if (!is.numeric(var)) stop(sprintf("%s is not a numeric", var_label))
  if (sum(!is.finite(var)) > 0) stop(sprintf("%s has non-finite elements", var_label))
  TRUE
}

Try the TriDimRegression package in your browser

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

TriDimRegression documentation built on Sept. 13, 2023, 5:07 p.m.