R/constraints.checkMinLength.R

Defines functions constraints.checkMinLength

Documented in constraints.checkMinLength

#' Check if minimum character length constraint is met
#' @description Specify the minimum length of a character
#' @param constraint numeric constraint, minimum character length
#' @param value character to meet the constraint
#' @return TRUE if character length is equal to or greater than the constraint 
#' @rdname constraints.checkMinLength
#' @export
#' 
#' @seealso \href{https://specs.frictionlessdata.io//table-schema/#constraints}{Constraints specifications}
#' 
#' @examples 
#' 
#' constraints.checkMinLength(constraint = list(3), value = "hi")
#' 
#' constraints.checkMinLength(constraint = 2, value = "hello")

constraints.checkMinLength <- function(constraint, value){
  
  if (is.null(value)) return(TRUE)
  
  if (all(nchar(value) >= constraint)) return(TRUE)
  
  return(FALSE)
}

Try the tableschema.r package in your browser

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

tableschema.r documentation built on Sept. 30, 2022, 1:06 a.m.