R/fCheckFLXCols.R

Defines functions fCheckFLXCols

Documented in fCheckFLXCols

#' Given a dataframe and a column name that you would expect to find within (e.g. "NEE_VUT_USTAR50"), this function checks whether the column exists.
#' If it does, it's exported as a vector.
#' If the column is not found, an error message is presented and NA values are supplied to the vector.
#' @export
#' @title Check whether column exists and export numeric vector
#' @param dat a dataframe.
#' @param col a column name.


# fCheckFLXCols - Given a dataframe and a column name that you would expect to find within (e.g. "NEE_VUT_USTAR50"), this function checks whether the column exists:
# If it does, it's exported as a vector.
# If the column is not found, an error message is presented and NA values are supplied to the vector.
fCheckFLXCols <- function(dat, col) {
  if ( !(col %in% colnames(dat)) ) { warning( "Variable column not found" ); return(NA)
  } else {
    as.numeric(dat[,col])
  }
}
ksmiff33/FluxSynthU documentation built on Dec. 15, 2020, 10:29 p.m.