R/validate_order_columns.R

Defines functions validate_order_columns

validate_order_columns <- function(data, cols){
  # First verify no NAs.
  cols <- unlist(cols)
  if(any(is.na(cols))) stop("Columns for ordering has at least one NA")
  # If character, verify that all elements are column names.
  if(is.character(cols)){
    bad_names <- cols[which(!(cols %in% colnames(data)))]
    if(length(bad_names) > 0)
      stop("Ordering columns not found in data: ",
           paste(bad_names, collapse = ", "))
    
  } else {
    # If numeric, verify that all values are within the correct interval.
    if(is.numeric(cols)){
      cols <- as.integer(cols)
      if(any(cols <= 0, cols > ncol(data)))
        stop("Invalid ordering column indices specified")
    } else {
      stop("Invalid column specification passed to ordering argument")
    }
  }
}

Try the distfreereg package in your browser

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

distfreereg documentation built on April 4, 2025, 12:30 a.m.