knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo = TRUE )
The R package cder
provides a simple interface to the CDEC
Webservice. Getting CDEC data with cder
is easy, just pass a
station code to cdec_query()
:
# get data for CDEC station NSL cdec_query("NSL")
The CDEC web service uses some default values for the duration code, sensor number, and start/end dates. However, these default values vary from station to station, and sometimes a station will return no data by default. It's generally a good idea to specify these yourself:
station = "NSL" duration = "event" # or "E" sensor = 100 # electrical conductivity start.date = "2023-01-01" end.date = "2023-01-05" cdec_query(station, sensor, duration, start.date, end.date)
The web service supports multiple stations and sensors:
# get data for CDEC stations NSL and HUN stations = c("NSL", "HUN") # get electrical conductivity and stage sensors = c(100, 1) start.date = "2023-01-01" end.date = "2023-01-05" cdec_query(stations, sensors, "hourly", start.date, end.date)
Certain CDEC stations may store non-numeric data flags in the Value
column instead of in the DataFlag column, resulting in parsing issues.
For example, flow data at SGN (Sugar Creek near Callahan) will
sometimes use the codes "ART" and "BRT" to signify discharge at stages
above or below the available rating table. cder
reexports
readr::problems()
to allow you to view these parsing problems, and
additionally writes the problematic rows to a temporary file to
facilitate further investigation.
sgn = cdec_query('SGN', 20, start.date = "2022-07-02", end.date = "2022-07-03") problems(sgn)
That's it! The CDEC Webservice currently does not support querying
station metadata. To browse station data, use the
Station Search tool
or Locator Map. These
URLs can also be accessed by calling cdec_search_stations()
and
cdec_map()
, respectively. See help("cdec-search")
for more
information.To access the metadata page for a particular station, use
cdec_meta()
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.