#' 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])
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.