R/validation.R

Defines functions validate_missing_values validate_no_zeros validate_Large_numbers validate_negatives validate_iregulars validate_no_decimals

#' #' @export
#' #' @rdname validation
#' #'
# validate_MA <- function(input) {
#   if (input == 1) {
#     "Duplicates the column. Please select another value"
#   } else {
#     NULL
#   }
# }

#' @export
#' @rdname validation
#'
validate_no_decimals <- function(input) {
  c <- stringi::stri_detect_fixed(input,".")
  if (c == TRUE) {
    "No decimals allowed"
  } else {
    NULL
  }
}
#' @export
#' @rdname validation
#'
validate_iregulars <- function(input) {
  single_nums <- unlist(stringr::str_split(input, ","))
  c <- !is.na(as.numeric(single_nums))
  if (is.element(FALSE, c)) {
    "Please choose a value!"
  } else {
    NULL
  }
}
#' @export
#' @rdname validation
#'
validate_negatives <- function(input) {
  single_nums <- unlist(stringr::str_split(input, ","))
  if (any(single_nums < 0)) {
    "Please choose a positive value!"
  } else {
    NULL
  }
}


#' @export
#' @rdname validation
#'
validate_Large_numbers <- function(input) {
  single_nums <- unlist(stringr::str_split(input, ","))
  if (any(single_nums > 400)) {
    "Please choose a smaller value!"
  } else {
    NULL
  }
}



#' @export
#' @rdname validation
#'
validate_no_zeros <- function(input) {
  single_nums <- unlist(stringr::str_split(input, ","))
  if (any(single_nums == 0)) {
    "Do not include zeros!"
  } else {
    NULL
  }
}

#' @export
#' @rdname validation
#'
#
validate_missing_values <- function(res,var) {
  col <- res[,var]
  if(any(is.na(col))) {
    "Please choose another variable. Calculations do not allow missing values!"
  } else {
    NULL
  }
}
lubrunn/DSP_App_Abgabe documentation built on Dec. 21, 2021, 11:51 a.m.