R/hasColumn.R

Defines functions hasColumn

Documented in hasColumn

#' Check whether a column is found in a data set
#'
#' Checks whether a specified column is found in a specified data set
#'
#' @param columnName The column to look for.
#' @param data the data.frame to search.
#' @return logical scalar. TRUE if the column is found. FALSE otherwise
#'
#' @examples
#' safetyGraphics:::hasColumn(columnName="PARAM",data=safetyData::adam_adlbc) #TRUE
#' safetyGraphics:::hasColumn(columnName="Not_a_column",data=safetyData::adam_adlbc) #FALSE
#'
#' @keywords internal

hasColumn <- function(columnName, data){
  stopifnot(
    typeof(columnName)=="character" || is.null(columnName),
    length(columnName)==1  || is.null(columnName),
    is.data.frame(data)
  )
  
  if(is.null(columnName)){
    return(FALSE)
  } else {
    return(toupper(columnName) %in% toupper(colnames(data)))  
  }
  
}

Try the safetyGraphics package in your browser

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

safetyGraphics documentation built on Dec. 28, 2022, 1:58 a.m.