get_wq_report_data() returns a water quality data report for a set of analytes (of the same media type) and discrete monitoring stations, across a specified date range supplied by the user. The function also provides arguments for the inclusion of guidelines and QAQC data.#' TODO: EnviroData API should return timezone information to avoid future issues.

get_wq_report_data(
  start_date,
  end_date,
  stations,
  analytes,
  media,
  guidelines = NULL,
  includeQaQc = TRUE,
  make_nice_names = FALSE
)

Arguments

start_date

A character string indicating the lower end of the date range. Must be formatted as e.g., 2012-Jan-05.

end_date

A character string indicating the upper end of the date range. Must be formatted as e.g., 2012-Jan-05.

stations

A character string or vector or list of strings of one or more valid station names.

Users may define monitoring locations themselves, but are advised to use the Location column from return values of get_wq_locations_list and get_metadata.

analytes

A character string or vector or list of strings of analyte names matching the full, back-end analyte names used by EnviroData.

Users may define analtyes themselves, but are advised to use the Analyte column from return values of get_wq_locations_details.

media

A character string indicating the media type for the request. Only one media type is allowed per function call.

Users may define media type themselves, but are advised to use the MediaType column from the return value of get_wq_locations_details.

guidelines

A character string or vector or list of character strings of guideline names in short format e.g., ART1_CA.

Users may define use guideline names listed on the Guidelines page in their EnviroData tenant or use the Guideline column from the return value of get_guideline_details.

Specified guidelines must exist for the specified media type and the analytes requested must be linked to the guideline in EnviroData.

includeQaQc

A logical value. If TRUE, will include QAQC data with request.

make_nice_names

A logical value. If TRUE will include the column NiceAnalyteNames.

Value

A long-format dataframe of water quality data containing the following columns:

  • Id - TODO: Add description..

  • Location - Names of station names supplied by the user.

  • DateTime - Date and time sample was taken. Automatically converted to POSIXct format and assigned the timezone of the user's computer.

  • Analyte - Analyte names supplied by the user matching the name as stored in the EnviroData database.

  • DisplayName - Analyte names as seen in the EnviroData UI.

  • Value - The lab result associated with each unique record.

  • Unit - The units associated with the lab result for each unique record.

  • DL - The detection limit associated with the analyte and analytical method used.

  • Guideline - The short names of guidelines supplied by the user. Will be blank for analytes that do not have values for any of the specified guidelines. Optional

  • MediaType - The sample media specified by the user.

  • SampleType - The type of sample each record is associated with. TODO: Add list of possible values and definitions for SampleType.

  • LabSampleId - The lab-assigned ID for the sample.

  • ClientSampleID - The client-assigned ID for the sample, usually obtained from the filled in COC (by the field crew) or the label on sample bottle.

  • COC Code - The Chain Of Custody number assigned by the lab.

  • Datum - Depth reference or the point from which depth is measured.

  • DatumDepthHeightValue - Depth or height, in meters, at which sample is taken.

  • Flags - TODO: Add description.

  • ComparisonOperation - TODO: Add description.

  • HasError - TODO: Add description.

  • NiceAnalyteName - Simplified analyte names presented in snake_case and excluding special characters.

  • 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.

Important events and metadata about calls of get_wq_report_data() are documented by the EnviroDataR logger in the log file edr_logs.txt. More information about the EnviroDataR logger can be found in vignette("envirodatar_request_logger").

Examples

# Create basic water quality report
start_date <- "2012-01-27"
end_date <- "2016-04-16"
wq_stations <- "WQ-1"
analytes <- "selenium-Dissolved_Concentration (liquid)"
media <- "Seawater"
guidelines <- c("BC_WWQG_LTAVE", "BC_AWQG_LTAVE")

wq_report_data <- get_wq_report_data(
start_date = start_date,
end_date = end_date,
station = wq_stations,
analytes = analytes,
media = media,
guidelines = guidelines,
includeQaQc = FALSE)

# Obtain argument values from `get_wq_locations_list()`,
# `get_wq_locations_details()` & `get_guideline_details()`

start_date <- "2012-01-27"
end_date <- "2016-04-16"

wq_location_data <- get_wq_locations_list()
wq_locations <- discrete_station_data$Location

wq_location_details <- get_wq_locations_details()
analytes <- unique(wq_location_details$Analyte)
media <- unique(wq_location_details$Media)

guideline_details <- get_guideline_details()
guidelines <- guideline_details$Guideline

wq_report_data <- get_wq_report_data(
start_date = start_date,
end_date = end_date,
station = wq_stations,
analytes = analytes,
media = media,
guidelines = guidelines,
includeQaQc = FALSE)