Skip to content
Snippets Groups Projects
populateParameterINFO.r 2.99 KiB
Newer Older
  • Learn to ignore specific revisions
  • Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' Populate Parameter Information Columns
    #'
    #' Populates INFO data frame with additional user-supplied information concerning the measured parameter.
    #'
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' @param localINFO dataframe with value and code columns. Default is INFO
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' @param parameterCd string USGS parameter code
    #' @param interactive logical Option for interactive mode.  If true, there is user interaction for error handling and data checks.
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' @return localINFO dataframe
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' @export
    #' @examples
    #' #This example requires an internet connection to run
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' INFO <- getSiteFileData('01594440')
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' parameterCd <- "00175"
    #' parameterData <- getParameterInfo(parameterCd,interactive=interactive)
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    #' INFO$param.nm <- parameterData$parameter_nm
    #' INFO$param.units <- parameterData$parameter_units
    #' INFO$paramShortName <- parameterData$srsname
    #' INFO$paramNumber <- parameterData$parameter_cd
    #' INFO <- populateParameterINFO(parameterCd,interactive=FALSE)
    populateParameterINFO <- function(parameterCd, localINFO=INFO, interactive=TRUE){
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
      if (nzchar(parameterCd)){
        if(interactive){
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("Your water quality data are for parameter number", localINFO$paramNumber, "which has the name:'", localINFO$param.nm, "'.\n")
          cat("Typically you will want a shorter name to be used in graphs and tables. The suggested short name is:'", localINFO$paramShortName, "'.\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("If you would like to change the short name, enter it here, otherwise just hit enter (no quotes):")
          shortNameTemp <- readline()
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          if (nchar(shortNameTemp)>0) localINFO$paramShortName <- shortNameTemp
          cat("The units for the water quality data are: ", localINFO$param.units, ".\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("It is helpful to set up a constiuent abbreviation when doing multi-constituent studies, enter a unique id (three or four characters should work something like tn or tp or NO3).\nIt is case sensitive.  Even if you don't feel you need an abbreviation you need to enter something (no quotes):\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$constitAbbrev <- readline()
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
        } else {
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$constitAbbrev <- localINFO$paramShortName
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
        }
      } else {
        if (interactive){
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$paramNumber <- NA
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("Enter a long name for the water quality data (no quotes):\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$param.nm <- readline()
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("Enter a short name to be used in graphs and tables(no quotes):\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$paramShortName <- readline()
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("It is helpful to set up a constiuent abbreviation when doing multi-constituent studies, enter a unique id (three or four characters should work something like tn or tp or NO3).\nIt is case sensitive.  Even if you don't feel you need an abbreviation you need to enter something (no quotes):\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$constitAbbrev <- readline()
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          cat("Enter the units of the water quality data(no quotes):\n")
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$param.units <- readline()
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
        } else {
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
          localINFO$paramNumber <- NA
          localINFO$param.nm <- NA
          localINFO$paramShortName <- NA
          localINFO$constitAbbrev <- NA
          localINFO$param.units <- NA      
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
      return(localINFO)
    
    Laura A DeCicco's avatar
    Laura A DeCicco committed
    }