CalculateGuidelinesWithRefSt() gives users direct access to the EnviroData microservice for calculating guidelines for use on external datasets (i.e., those not stored on EnviroData). It is a wrapper for calculate_guideline() that allows the user to calculate endpoints for more than one guideline and specify the EDR host URL. It also returns guideline and cofactor data in a more user-friendly format.

CalculateGuidelinesWithRefSt(
  df_with_ref_data,
  guidelines = NULL,
  compareGuideline = FALSE,
  wrd_url = EDR_URL
)

Arguments

df_with_ref_data

A dataframe of columns containing data and the cofactors necessary to calculate endpoints for a set of analytes. The columns required are described below. If extra columns are provided, the function will ignore them without breaking.

  • Site or Location: - The names of stations from which cofactors are used to calculate guidelines. Should be type character.

  • DateTime: The date and time samples were taken. All dates must be formatted as one of either %%Y-%%m-%%d and %%Y-%%b-%%d. Should be class POSIXct.

  • Analyte: - The EnviroData Analyte Name as stored in the EnviroData database, as opposed to the EnviroData DisplayName, seen in the EnviroData UI. As such, analyte names from external data may need standardization to match the required format before guidelines can be calculated. Should be type character.

  • Value: Lab result of analyte reported from water quality analyses. Should be type numeric.

  • Unit: Units of measurement for water quality lab results. Should be type character.

  • pH: The result for pH corresponding to each sample. Where lab pH is not available, pH (field) should be used to fill in the gaps. To be used for guideline calculations where pH is a required cofactor. Should be type numeric.

  • Hardness: Lab result for Hardness corresponding to each sample. To be used for guideline calculations where Hardness is a required cofactor. Should be type numeric.

  • Chloride: Lab result for Chloride corresponding to each sample. To be used for guideline calculations where Chloride is a required cofactor. Should be type numeric.

  • Temperature: Lab result for Temperature corresponding to each sample. To be used for guideline calculations where Temperature is a required cofactor. Should be type numeric.

  • ColorRef: Lab result for ColorRef corresponding to each sample. To be used for guideline calculations where ColorRef is a required cofactor. Should be type numeric.

guidelines

A character vector of one or more guidelines to be calculated. If guidelines='all', all possible guidelines will be calculated. If NULL the function will return reference data but not guidelines.

compareGuideline

A logical, passed to calculate_guideline. Keep as FALSE unless debugging. For now this has no effect on the output, but with TRUE the API request is slower.

wrd_url

A character vector containing the EnviroData server URL required, by the user. By default, the EDR_URL associated with the current session is used.

Value

The original dataframe with additional columns containing info on the calculated guidelines:

  • DisplayName: Analyte name as displayed in EnviroData UI.

  • Guideline: The guideline used in the calculation

  • GuidelineName: The name of the guideline used in the calculation.

  • Guideline Value: The value of the guideline used in the calculation

  • Guideline Unit: The unit of measurement for the selected guideline.

  • minGuideline: The lower limit for a given analyte according to the associated guideline. Will be NA if there isn't a guideline value for the given analyte.

  • maxGuideline: The upper limit for a given analyte according to the associated guideline. Will be NA if there isn't a guideline value for the given analyte.

Details

IMPORTANT: Users must obtain login credentials to the wqProcessing tenant to use this function. In addition, analyte names in external datasets will need to match the formatting used by the EnviroData Analyte Name.

Contact the Environmental Information Specialist assigned to your project or the Data Solutions Group for more assistance in this regard.

Examples


# example dates and analyte names
dates <- as.POSIXct(seq(2))
analytes_1 <- c("Cobalt (Co)-Total_Concentration (liquid)", "something else")

# minimal data frame for the request
input_1 <- data.frame(DateTime=dates, Analyte=analytes_1)

# second guideline field is empty because there was no matching analyte name
CalculateGuidelinesWithRefSt(input_1, "BC_AWQG_STMAX", compareGuideline=FALSE)

# this example requires cofactors
analytes_2 <- c("Copper (Cu)-Dissolved_Concentration (liquid)", 2)
cofactor_2 <- data.frame(pH = c(7, NA), Hardness = c(150, NA), DOC = c(3, NA))
input_2 <- data.frame(DateTime=dates, Analyte=analytes_2) |> cbind(cofactor_2)

# the second guideline is empty because we were missing its cofactors
CalculateGuidelinesWithRefSt(input_2, "BC_AWQG_STMAX", compareGuideline=FALSE)