#' Create 'INFO' metadata for EGRET/WQTDS analysis
#'
#' @param wq_data a dataframe of water quality data generated by getwq(). Must have a single station and parameter.
#' @param paStart Starting month of period of analysis. Defaults to 10. Used in most EGRET functions
#' @param paLong Length in number of months of period of analysis. Defaults to 12. Used in most EGRET functions
#' @param watershedKm Watershed area, used to calculate runoff. Defaults to 1
#' @param stationColumn name of station column in dataset.
#'
#' @return a single-row dataframe with EGRET-style metadata. See ?EGRET::INFOdataframe for more information.
#' @export
#'
#' @examples
#' INFO <- createInfo(wq_data = wqDat)
createInfo <- function(wq_data, paStart = 10, # see output for ?EGRET::INFOdataframe. starting month for analysis
paLong = 12, watershedKm = 1, stationColumn = "stn"
) { # creates EGRET-style INFO metadata object from WQ data
### TODO: see ?INFOdataframe to improve input checks. esp. param.units - do unit conversions to mg/L if necessary
if ("units" %in% names(wq_data)) {
param.units <- wq_data$units[1]
} else {
param.units <- "unknown"
}
shortName <- wq_data[, stationColumn][1]
paramShortName <- gsub(x = wq_data$param[1], pattern = " |,", replacement = "")
paramShortName <- gsub(x = paramShortName, pattern = "-|[+]", replacement = "")
drainSqKm <- watershedKm # Used for calculating runoff
constitAbbrev <- paramShortName
staAbbrev <- shortName
outputDF <- data.frame(param.units, shortName, paramShortName, drainSqKm,
constitAbbrev, staAbbrev, paStart, paLong)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.