R/check_ts_data.R

Defines functions check_time_data_format check_cpt_format

Documented in check_cpt_format check_time_data_format

#' @title Check data format for TS anaylysis
#'
#' @description Check whether the timename column exists & is integers
#'
#' @param data dataset to check
#'
#' @return TRUE or FALSE
#'
#' @export

check_time_data_format <- function(data)
{
  # check if timename column exists
  if (!(data$metadata$timename %in% colnames(data$covariates)))
  {
    message("The timename column does not exist.")
    return(FALSE)
  }

  # check if the time column can be coerced to integers
  if (length(unique(as.integer(unlist(data$covariates[,data$metadata$timename])))) != NROW(data$covariates))
  {
    message("The timename column cannot be coerced to integers without losing information.")
    return(FALSE)
  }

  return(TRUE)
}

#' @title Check changepoint model format for TS select
#'
#' @description Check whether the changepoint model is a changepoint model
#'
#' @param cpt_model model to check
#'
#' @return TRUE or FALSE
#'
#' @export

check_cpt_format <- function(cpt_model)
{
  # check if timename column exists
  if (!(class(cpt_model)[[1]] == 'TS_on_LDA'))
  {
    message("Not a changepoint model")
    return(FALSE)
  }

  return(TRUE)
}
weecology/MATSS-LDATS documentation built on Nov. 5, 2019, 12:07 p.m.