The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Title: Extract and Tidy Canadian 'Hydrometric' Data
Version: 1.0.0
Description: Provides functions to access historical and real-time national 'hydrometric' data from Water Survey of Canada data sources and then applies tidy data principles.
License: Apache License (== 2.0) | file LICENSE
URL: https://docs.ropensci.org/tidyhydat/, https://github.com/ropensci/tidyhydat/
BugReports: https://github.com/ropensci/tidyhydat/issues/
Depends: R (≥ 4.2.0)
Imports: cli (≥ 1.0.0), crayon (≥ 1.3.4), DBI (≥ 0.7), dbplyr (≥ 1.1.0), dplyr (≥ 0.7.4), httr2 (≥ 1.0.0), lubridate (≥ 1.6.0), rappdirs (≥ 0.3.1), readr (≥ 1.1.1), rlang (≥ 0.1.2), RSQLite (≥ 2.0), tidyr (≥ 0.7.1)
Suggests: ggplot2, httptest2, knitr, rmarkdown, testthat (≥ 3.0.0), covr
Config/testthat/edition: 3
VignetteBuilder: knitr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.3
NeedsCompilation: no
Packaged: 2026-02-02 21:04:37 UTC; sam.albers
Author: Sam Albers ORCID iD [aut, cre, cph] (Copyright holder 2022-2025), Province of British Columbia [cph] (Copyright holder 2017-2022), Tula Foundation [cph] (Copyright holder 2025-present), David Hutchinson [ctb], Dewey Dunnington [ctb], Ryan Whaley [ctb], Government of Canada [dtc], Luke Winslow [rev] (Reviewed for rOpenSci), Laura DeCicco [rev] (Reviewed for rOpenSci)
Maintainer: Sam Albers <sam.albers@gmail.com>
Repository: CRAN
Date/Publication: 2026-02-03 06:10:10 UTC

tidyhydat: Extract and Tidy Canadian 'Hydrometric' Data

Description

logo

Provides functions to access historical and real-time national 'hydrometric' data from Water Survey of Canada data sources and then applies tidy data principles.

Author(s)

Maintainer: Sam Albers sam.albers@gmail.com (ORCID) (Copyright holder 2022-2025) [copyright holder]

Other contributors:

References

To download the latest version of hydat please:

For more information on tidy data please see

For more information on HYDAT and ECCC data sources

See Also

Useful links:


All Canadian stations

Description

A shorthand to avoid having always call hy_stations or realtime_stations. Populated by both realtime and historical data from HYDAT.

Usage

allstations

Format

A tibble with 5 variables:

Source

HYDAT, Meteorological Service of Canada datamart


Get all available flow data (final + provisional)

Description

Convenience function that combines final historical data (from HYDAT or web service) with provisional real-time data in a single call.

Usage

available_flows(
  station_number,
  start_date = NULL,
  end_date = Sys.Date(),
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

start_date

Start date for data retrieval in YYYY-MM-DD format. Defaults to NULL (retrieves all available historical data).

end_date

End date for data retrieval in YYYY-MM-DD format. Defaults to current date (Sys.Date()).

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 6 variables:

Details

This function combines data from final and provisional data sources to provide a complete discharge record.

Data Sources and Priority

Historical (Final) Data:

The function automatically determines the best source for historical data:

Real-time (Provisional) Data:

Provisional data is retrieved from ECCC's real-time web service using the realtime_ws() function. This data covers approximately the last 18 months and is updated regularly. Since real-time data is collected at sub-daily intervals, values are aggregated to daily means to match the daily format of HYDAT data. For non-aggregated real-time data, use realtime_ws() directly.

Data Approval Status

The Approval column uses ECCC's terminology (see https://wateroffice.ec.gc.ca/contactus/faq_e.html):

Value

A tibble with class available combining final and provisional data with an additional Approval column indicating whether each record is "final" or "provisional". The object includes attributes for tracking data sources and query metadata.

See Also

Other available functions: available_levels()

Examples

## Not run: 
## Basic usage - get all available data
flows <- available_flows("08MF005")

## Multiple stations
flows <- available_flows(c("08MF005", "08NM116"))

## Get only recent data (last 2 years)
recent_flows <- available_flows(
  "08MF005",
  start_date = Sys.Date() - lubridate::years(2),
  end_date = Sys.Date()
)

## Force use of web service (when HYDAT not available)
flows_ws <- available_flows("08MF005", hydat_path = FALSE)

## End(Not run)


Get all available level data (final + provisional)

Description

Convenience function that combines final historical data (from HYDAT or web service) with provisional real-time data in a single call.

Usage

available_levels(
  station_number,
  start_date = NULL,
  end_date = Sys.Date(),
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

start_date

Start date for data retrieval in YYYY-MM-DD format. Defaults to NULL (retrieves all available historical data).

end_date

End date for data retrieval in YYYY-MM-DD format. Defaults to current date (Sys.Date()).

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 6 variables:

Details

This function combines data from final and provisional data sources to provide a complete water level record.

Data Sources and Priority

Historical (Final) Data:

The function automatically determines the best source for historical data:

Real-time (Provisional) Data:

Provisional data is retrieved from ECCC's real-time web service using the realtime_ws() function. This data covers approximately the last 18 months and is updated regularly. Since real-time data is collected at sub-daily intervals, values are aggregated to daily means to match the daily format of HYDAT data. For non-aggregated real-time data, use realtime_ws() directly.

Data Approval Status

The Approval column uses ECCC's terminology (see https://wateroffice.ec.gc.ca/contactus/faq_e.html):

Value

A tibble with class available combining final and provisional data with an additional Approval column indicating whether each record is "final" or "provisional". The object includes attributes for tracking data sources and query metadata.

See Also

Other available functions: available_flows()

Examples

## Not run: 
## Basic usage - get all available data
levels <- available_levels("08MF005")

## Multiple stations
levels <- available_levels(c("08MF005", "08NM116"))

## Get only recent data (last 2 years)
recent_levels <- available_levels(
  "08MF005",
  start_date = Sys.Date() - lubridate::years(2),
  end_date = Sys.Date()
)

## Force use of web service (when HYDAT not available)
levels_ws <- available_levels("08MF005", hydat_path = FALSE)

## End(Not run)


Download and set the path to HYDAT

Description

Download the HYDAT sqlite database. This database contains all the historical hydrometric data for Canada's integrated hydrometric network. The function will check for a existing sqlite file and won't download the file if the same version is already present.

Usage

download_hydat(dl_hydat_here = NULL, ask = TRUE)

Arguments

dl_hydat_here

Directory to the HYDAT database. The path is chosen by the rappdirs package and is OS specific and can be view by hy_dir(). This path is also supplied automatically to any function that uses the HYDAT database. A user specified path can be set though this is not the advised approach. It also downloads the database to a directory specified by hy_dir().

ask

Whether to ask (as TRUE/FALSE) if HYDAT should be downloaded. If FALSE the keypress question is skipped.

Examples

## Not run: 
download_hydat()

## End(Not run)


hy_agency_list function

Description

AGENCY look-up Table

Usage

hy_agency_list(hydat_path = NULL)

Arguments

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

Value

A tibble of agencies

Source

HYDAT

See Also

Other HYDAT functions: hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_agency_list()

## End(Not run)


Extract annual max/min instantaneous flows and water levels from HYDAT database

Description

Provides wrapper to turn the ANNUAL_INSTANT_PEAKS table in HYDAT into a tidy data frame of instantaneous flows and water levels. station_number and prov_terr_state_loc can both be supplied.

Usage

hy_annual_instant_peaks(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_year = NULL,
  end_year = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_year

First year of the returned record

end_year

Last year of the returned record

Value

A tibble of hy_annual_instant_peaks.

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
## Multiple stations province not specified
hy_annual_instant_peaks(station_number = c("08NM083", "08NE102"))

## Multiple province, station number not specified
hy_annual_instant_peaks(prov_terr_state_loc = c("AB", "YT"))

## End(Not run)


Extract annual statistics information from the HYDAT database

Description

Provides wrapper to turn the ANNUAL_STATISTICS table in HYDAT into a tidy data frame of annual statistics. Statistics provided include MEAN, MAX and MIN on an annual basis.

Usage

hy_annual_stats(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_year = "ALL",
  end_year = "ALL"
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_year

First year of the returned record

end_year

Last year of the returned record

Format

A tibble with 8 variables:

Value

A tibble of hy_annual_stats.

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
## Multiple stations province not specified
hy_annual_stats(station_number = c("08NM083", "05AE027"))

## Multiple province, station number not specified
hy_annual_stats(prov_terr_state_loc = c("AB", "SK"))

## End(Not run)


Extract all daily water level and flow measurements

Description

A thin wrapper around hy_daily_flows and 'hy_daily_levels“ that returns a data frames that contains both parameters. All arguments are passed directly to these functions.

Usage

hy_daily(
  station_number = NULL,
  prov_terr_state_loc = NULL,
  hydat_path = NULL,
  ...
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

...

See hy_daily_flows() arguments

Format

A tibble with 5 variables:

Value

A tibble of daily flows and levels

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_daily(station_number = c("02JE013", "08MF005"))

## End(Not run)


Extract daily flows information from HYDAT database or web service

Description

Provides wrapper to turn the DLY_FLOWS table in HYDAT (or historical web service) into a tidy data frame of daily flows. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large tibble for hy_daily_flows.

Usage

hy_daily_flows(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL,
  symbol_output = "code"
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

symbol_output

Set whether the raw code, or the english or the french translations are outputted. Default value is code.

Format

A tibble with 5 variables:

Details

The hydat_path argument controls the data source:

Value

A tibble of daily flows

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
# download_hydat()
hy_daily_flows(
  station_number = c("08MF005"),
  start_date = "1996-01-01", end_date = "2000-01-01"
)

hy_daily_flows(prov_terr_state_loc = "PE")

## End(Not run)


Extract daily levels information from HYDAT database or web service

Description

Provides wrapper to turn the DLY_LEVELS table in HYDAT (or historical web service) into a tidy data frame. The primary value returned by this function is water level. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_daily_levels.

Usage

hy_daily_levels(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL,
  symbol_output = "code"
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

symbol_output

Set whether the raw code, or the english or the french translations are outputted. Default value is code.

Format

A tibble with 5 variables:

Details

The hydat_path argument controls the data source:

Value

A tibble of daily levels

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_daily_levels(
  station_number = c("02JE013", "08MF005"),
  start_date = "1996-01-01", end_date = "2000-01-01"
)

hy_daily_levels(prov_terr_state_loc = "PE")

## End(Not run)


DATA SYMBOLS look-up table

Description

A look table for data symbols

Usage

hy_data_symbols

Format

A tibble with 5 rows and 3 variables:

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()


DATA TYPES look-up table

Description

A look table for data types

Usage

hy_data_types

Format

A tibble with 5 rows and 3 variables:

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()


Extract datum list from HYDAT database

Description

DATUM look-up Table

Usage

hy_datum_list(hydat_path = NULL)

Arguments

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

Value

A tibble of DATUMS

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_datum_list()

## End(Not run)


Output OS-independent path to the HYDAT sqlite database

Description

Provides the download location for download_hydat in an OS independent manner.

Usage

hy_dir(...)

Arguments

...

arguments potentially passed to rappdirs::user_data_dir

Examples

## Not run: 
hy_dir()

## End(Not run)


Extract monthly flows information from the HYDAT database

Description

Tidy data of monthly flows information from the monthly_flows HYDAT table. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_monthly_flows.

Usage

hy_monthly_flows(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

Format

A tibble with 8 variables:

Value

A tibble of monthly flows.

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_monthly_flows(
  station_number = c("02JE013", "08MF005"),
  start_date = "1996-01-01", end_date = "2000-01-01"
)

hy_monthly_flows(prov_terr_state_loc = "PE")

## End(Not run)


Extract monthly levels information from the HYDAT database

Description

Tidy data of monthly river or lake levels information from the DLY_LEVELS HYDAT table. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_monthly_levels.

Usage

hy_monthly_levels(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

Format

A tibble with 8 variables:

Value

A tibble of monthly levels.

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_monthly_levels(
  station_number = c("02JE013", "08MF005"),
  start_date = "1996-01-01", end_date = "2000-01-01"
)

hy_monthly_levels(prov_terr_state_loc = "PE")

## End(Not run)

This function is deprecated in favour of generic plot methods

Description

This is an easy way to visualize a single station using base R graphics. More complicated plotting needs should consider using ggplot2. Inputting more 5 stations will result in very busy plots and longer load time. Legend position will sometimes overlap plotted points.

Usage

hy_plot(
  station_number = NULL,
  Parameter = c("Flow", "Level", "Suscon", "Load")
)

Arguments

station_number

A (or several) seven digit Water Survey of Canada station number.

Parameter

Parameter of interest. Either "Flow" or "Level".


Extract regional office list from HYDAT database

Description

OFFICE look-up Table

Usage

hy_reg_office_list(hydat_path = NULL)

Arguments

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

Value

A tibble of offices

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_reg_office_list()

## End(Not run)


Get the version date of HYDAT that is current on the ECCC website

Description

Retrieve the date of the HYDAT version available for download.

Usage

hy_remote()

Extract daily sediment load information from the HYDAT database

Description

Provides wrapper to turn the SED_DLY_LOADS table in HYDAT into a tidy data frame of daily sediment load information. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_sed_daily_loads.

Usage

hy_sed_daily_loads(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

Format

A tibble with 4 variables:

Value

A tibble of daily suspended sediment loads

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_sed_daily_loads(prov_terr_state_loc = "PE")

## End(Not run)


Extract daily suspended sediment concentration information from the HYDAT database

Description

Provides wrapper to turn the SED_DLY_SUSCON table in HYDAT into a tidy data frame of daily suspended sediment concentration information. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_sed_daily_suscon.

Usage

hy_sed_daily_suscon(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL,
  symbol_output = "code"
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

symbol_output

Set whether the raw code, or the english or the french translations are outputted. Default value is code.

Format

A tibble with 5 variables:

Value

A tibble of daily suspended sediment concentration

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_sed_daily_suscon(station_number = "01CE003")

## End(Not run)


Extract monthly flows information from the HYDAT database

Description

Tidy data of monthly loads information from the SED_DLY_LOADS HYDAT table. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_sed_monthly_loads.

Usage

hy_sed_monthly_loads(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

Format

A tibble with 8 variables:

Value

A tibble of monthly sediment loads.

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_sed_monthly_loads(station_number = "01CE003")

## End(Not run)


Extract monthly flows information from the HYDAT database

Description

Tidy data of monthly suspended sediment concentration information from the SED_DLY_SUSCON HYDAT table. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_sed_monthly_suscon.

Usage

hy_sed_monthly_suscon(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

Format

A tibble with 8 variables:

Value

A tibble of monthly suspended sediment concentrations.

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_sed_monthly_suscon(station_number = "08MF005")

## End(Not run)

Extract instantaneous sediment sample information from the HYDAT database

Description

Provides wrapper to turn the hy_sed_samples table in HYDAT into a tidy data frame of instantaneous sediment sample information. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. That is a large vector for hy_sed_samples.

Usage

hy_sed_samples(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

Format

A tibble with 19 variables:

Value

A tibble of instantaneous sediment samples data

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_sed_samples(station_number = "01CA004")

## End(Not run)


Extract instantaneous sediment sample particle size distribution information from the HYDAT database

Description

Provides wrapper to turn the hy_sed_samples_psd table in HYDAT into a tidy data frame of instantaneous sediment sample particle size distribution. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations() table are returned. That is a large vector for hy_sed_samples_psd.

Usage

hy_sed_samples_psd(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL,
  start_date = NULL,
  end_date = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

start_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

end_date

Leave blank if all dates are required. Date format needs to be in YYYY-MM-DD. Date is inclusive.

Format

A tibble with 5 variables:

Value

A tibble of sediment sample particle size data

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_sed_samples_psd(station_number = "01CA004")

## End(Not run)


Set the default database path

Description

For many reasons, it may be convenient to set the default database location to somewhere other than the global default. Users may wish to use a previously downloaded version of the database for reproducibility purposes, store hydat somewhere other than hy_dir().

Usage

hy_set_default_db(hydat_path = NULL)

Arguments

hydat_path

The path to the a HYDAT sqlite3 database file (e.g., hy_test_db)

Value

returns the previous value of hy_default_db.

Examples

## Not run: 
# set default to the test database
hy_set_default_db(hy_test_db())

# get the default value
hy_default_db()

# set back to the default db location
hy_set_default_db(NULL)

## End(Not run)


Open a connection to the HYDAT database

Description

This function gives low-level access to the underlying HYDAT database used by other functions. Many of these tables are too large to load into memory, so it is best to use dplyr to dplyr::filter() them before using dplyr::collect() to read them into memory.

Usage

hy_src(hydat_path = NULL)

hy_src_disconnect(src)

Arguments

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

src

A as returned by hy_src().

Value

A SQLite DBIConnection

See Also

download_hydat()

Examples

## Not run: 
library(dplyr)

# src is a src_sqlite
src <- hy_src(hydat_path = hy_test_db())
src_tbls(src)

# to get a table, use dplyr::tbl()
tbl(src, "STATIONS")

# one you're sure the results are what you want
# get a data.frame using collect()
tbl(src, "STATIONS") |>
  filter(PROV_TERR_STATE_LOC == "BC") |>
  collect()

# close the connection to the database
hy_src_disconnect(src)

## End(Not run)

Extract station information from the HYDAT database

Description

Provides wrapper to turn the hy_stations table in HYDAT into a tidy data frame of station information. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned. This is the entry point for most analyses is tidyhydat as establish the stations for consideration is likely the first step in many instances.

Usage

hy_stations(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 15 variables:

Value

A tibble of stations and associated metadata

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
## Multiple stations province not specified
hy_stations(station_number = c("08NM083", "08NE102"))

## Multiple province, station number not specified
hy_stations(prov_terr_state_loc = c("AB", "YT"))

## End(Not run)


Extract station data collection from HYDAT database

Description

hy_stn_data_coll look-up Table

Usage

hy_stn_data_coll(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 6 variables:

Value

A tibble of hy_stn_data_coll

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_stn_data_coll(station_number = c("02JE013", "08MF005"))

## End(Not run)


Extract station data range from HYDAT database

Description

hy_stn_data_range look-up Table

Usage

hy_stn_data_range(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 6 variables:

Value

A tibble of hy_stn_data_range

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_op_schedule(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_stn_data_range(station_number = c("02JE013", "08MF005"))

## End(Not run)


Extract station datum conversions from HYDAT database

Description

hy_stn_datum_conv look-up Table

Usage

hy_stn_datum_conv(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 4 variables:

Value

A tibble of hy_stn_datum_conv

Examples

## Not run: 
hy_stn_datum_conv(station_number = c("02JE013", "08MF005"))

## End(Not run)

Extract station datum unrelated from HYDAT database

Description

hy_stn_datum_unrelated look-up Table

Usage

hy_stn_datum_unrelated(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 4 variables:

Value

A tibble of hy_stn_datum_unrelated

Examples

## Not run: 
hy_stn_datum_unrelated()

## End(Not run)


Extract station operation schedule from HYDAT database

Description

hy_stn_op_schedule look-up Table

Usage

hy_stn_op_schedule(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 6 variables:

Value

A tibble of hy_stn_op_schedule

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_regulation(), hy_version()

Examples

## Not run: 
hy_stn_op_schedule(station_number = c("02JE013"))

## End(Not run)


Extract station regulation from the HYDAT database

Description

Provides wrapper to turn the hy_stn_regulation table in HYDAT into a tidy data frame of station regulation. station_number and prov_terr_state_loc can both be supplied. If both are omitted all values from the hy_stations table are returned.

Usage

hy_stn_regulation(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 4 variables:

STATION_NUMBER

Unique 7 digit Water Survey of Canada station number

Year_from

First year of use

Year_to

Last year of use

REGULATED

logical

Value

A tibble of stations, years of regulation and the regulation status

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_version()

Examples

## Not run: 
## Multiple stations province not specified
hy_stn_regulation(station_number = c("08NM083", "08NE102"))

## Multiple province, station number not specified
hy_stn_regulation(prov_terr_state_loc = c("AB", "YT"))

## End(Not run)


Extract station remarks from HYDAT database

Description

hy_stn_remarks look-up Table

Usage

hy_stn_remarks(
  station_number = NULL,
  hydat_path = NULL,
  prov_terr_state_loc = NULL
)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 4 variables:

Value

A tibble of hy_stn_remarks

Examples

## Not run: 
hy_stn_remarks(station_number = c("02JE013", "08MF005"))

## End(Not run)


Get the location of the HYDAT database

Description

The full HYDAT database needs to be downloaded from download_hydat, but for testing purposes, a small test database is included in this package. Use hydat_path = hy_test_db() in hy_* functions to explicitly use the test database; use hydat_path = hy_downloaded_db() to explicitly use the full, most recent downloaded database (this is also the path returned by hy_default_db()).

Usage

hy_test_db()

hy_downloaded_db()

hy_default_db()

Value

The file location of a HYDAT database.

See Also

hy_src, hy_set_default_db.

Examples

## Not run: 
hy_test_db()
hy_downloaded_db()
hy_default_db()

## End(Not run)


Extract version number from HYDAT database

Description

A function to get version number of hydat

Usage

hy_version(hydat_path = NULL)

Arguments

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

Value

version number and release date

Source

HYDAT

See Also

Other HYDAT functions: hy_agency_list(), hy_annual_instant_peaks(), hy_annual_stats(), hy_daily(), hy_daily_flows(), hy_daily_levels(), hy_data_symbols, hy_data_types, hy_datum_list(), hy_monthly_flows(), hy_monthly_levels(), hy_reg_office_list(), hy_sed_daily_loads(), hy_sed_daily_suscon(), hy_sed_monthly_loads(), hy_sed_monthly_suscon(), hy_sed_samples(), hy_sed_samples_psd(), hy_stations(), hy_stn_data_coll(), hy_stn_data_range(), hy_stn_op_schedule(), hy_stn_regulation()

Examples

## Not run: 
hy_version()

## End(Not run)


Parameter ID

Description

A tibble of parameter id codes and their corresponding explanation/description specific to the ECCC webservice

Usage

param_id

Format

A tibble with 8 rows and 7 variables:


Plot available data (final + provisional)

Description

This method plots combined final and provisional data, visually distinguishing between validated (final) and provisional records.

This method plots either daily time series data from HYDAT or realtime data from the datamart. These plots are intended to be convenient and quick methods to visualize hydrometric data.

Usage

## S3 method for class 'available'
plot(x = NULL, ...)

## S3 method for class 'hy'
plot(x = NULL, ...)

## S3 method for class 'realtime'
plot(x = NULL, Parameter = c("Flow", "Level"), ...)

Arguments

x

Object created by either a hy_daily_* or realtime_dd data retrieval function

...

passed to plot()

Parameter

Parameter of interest. Either "Flow" or "Level". Defaults to "Flow".

Methods (by class)

Examples

## Not run: 
# One station
flows <- available_flows("08MF005")
plot(flows)

## End(Not run)

## Not run: 
# One station
fraser <- hy_daily_flows("08MF005")
plot(fraser)

## End(Not run)

## Not run: 
# One station
fraser_realtime <- realtime_dd("08MF005")
plot(fraser_realtime)

## End(Not run)


Convenience function to pull station number from tidyhydat functions

Description

This function mimics dplyr::pull to avoid having to always type dplyr::pull(STATION_NUMBER). Instead we can now take advantage of autocomplete. This can be used with realtime_ and hy_ functions.

Usage

pull_station_number(.data)

Arguments

.data

A table of data

Value

A vector of station_numbers

Examples

## Not run: 

hy_stations(prov_terr_state_loc = "PE") |>
  pull_station_number() |>
  hy_annual_instant_peaks()

## End(Not run)


Add local datetime column to realtime tibble

Description

Adds local_datetime and tz_used columns based on either the most common timezone in the original data or a user supplied timezone. This function is meant to used in a pipe with the realtime_dd() function.

Usage

realtime_add_local_datetime(.data, set_tz = NULL)

Arguments

.data

Tibble created by realtime_dd

set_tz

A timezone string in the format of OlsonNames()

Details

Date from realtime_dd is supplied in UTC which is the easiest format to work with across timezones. This function does not change Date from UTC. Rather station_tz specifies the local timezone name and is useful in instances where realtime_add_local_datetime adjusts local_datetime to a common timezone that is not the station_tz. This function is most useful when all stations exist within the same timezone.

Examples

## Not run: 

realtime_dd(c("08MF005", "02LA004")) |>
  realtime_add_local_datetime()

## End(Not run)


Calculate daily means from higher resolution realtime data

Description

This function is meant to be used within a pipe as a means of easily moving from higher resolution data to daily means.

Usage

realtime_daily_mean(.data, na.rm = FALSE)

Arguments

.data

A data argument that is designed to take only the output of realtime_dd

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

Examples

## Not run: 
realtime_dd("08MF005") |> realtime_daily_mean()

## End(Not run)


Download a tibble of realtime river data from the last 30 days from the Meteorological Service of Canada datamart

Description

Download realtime river data from the last 30 days from the Meteorological Service of Canada (MSC) datamart. The function will prioritize downloading data collected at the highest resolution. In instances where data is not available at high (hourly or higher) resolution daily averages are used. Currently, if a station does not exist or is not found, no data is returned.

Usage

realtime_dd(station_number = NULL, prov_terr_state_loc = NULL)

Arguments

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 8 variables:

Value

A tibble of water flow and level values. The date and time of the query (in UTC) is also stored as an attribute.

See Also

Other realtime functions: realtime_stations(), realtime_ws()

Examples

## Not run: 
## Download from multiple provinces
realtime_dd(station_number = c("01CD005", "08MF005"))

## To download all stations in Prince Edward Island:
pei <- realtime_dd(prov_terr_state_loc = "PE")

## Access the time of query
attributes(pei)$query_time

## End(Not run)


Convenience function to plot realtime data

Description

This is an easy way to visualize a single station using base R graphics. More complicated plotting needs should consider using ggplot2. Inputting more 5 stations will result in very busy plots and longer load time. Legend position will sometimes overlap plotted points.

Usage

realtime_plot(station_number = NULL, Parameter = c("Flow", "Level"))

Arguments

station_number

A seven digit Water Survey of Canada station number. Can only be one value.

Parameter

Parameter of interest. Either "Flow" or "Level". Defaults to "Flow".

Value

A plot of recent realtime values

Examples

## Not run: 
## One station
realtime_plot("08MF005")

## Multiple stations
realtime_plot(c("07EC002", "01AD003"))

## End(Not run)


Download a tibble of active realtime stations

Description

An up to date dataframe of all stations in the Realtime Water Survey of Canada hydrometric network operated by Environment and Climate Change Canada

Usage

realtime_stations(prov_terr_state_loc = NULL)

Arguments

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.

Format

A tibble with 6 variables:

See Also

Other realtime functions: realtime_dd(), realtime_ws()

Examples

## Not run: 
## Available inputs for prov_terr_state_loc argument:
unique(realtime_stations()$prov_terr_state_loc)

realtime_stations(prov_terr_state_loc = "BC")
realtime_stations(prov_terr_state_loc = c("QC", "PE"))

## End(Not run)


Download realtime data from the ECCC web service

Description

Function to actually retrieve data from ECCC web service. The maximum number of days that can be queried depends on other parameters being requested. If one station is requested, 18 months of data can be requested. If you continually receiving errors when invoking this function, reduce the number of observations (via station_number, parameters or dates) being requested.

Usage

realtime_ws(
  station_number,
  parameters = NULL,
  start_date = Sys.Date() - lubridate::days(30),
  end_date = Sys.Date()
)

Arguments

station_number

Water Survey of Canada station number.

parameters

parameter ID. Can take multiple entries. Parameter is a numeric code. See param_id for some options though undocumented parameters may be implemented. Defaults to Water level provisional, Secondary water level, Tertiary water level, Discharge Provisional, Discharge, sensor, Water temperature, Secondary water temperature, Accumulated precipitation

start_date

Accepts either YYYY-MM-DD or YYYY-MM-DD HH:MM:SS. If only 'start date“ is supplied (i.e. YYYY-MM-DD) values are returned from the start of that day. Defaults to 30 days before current date. Time is supplied in UTC.

end_date

Accepts either YYYY-MM-DD or YYYY-MM-DD HH:MM:SS. If only 'end_date“ is supplied (i.e. YYYY-MM-DD) values are returned from the end of that day. Defaults to current date. Time is supplied in UTC.

Format

A tibble with 6 variables:

See Also

Other realtime functions: realtime_dd(), realtime_stations()

Examples

## Not run: 

ws_08 <- realtime_ws(
  station_number = c("08NL071", "08NM174"),
  parameters = c(47, 5)
)

fivedays <- realtime_ws(
  station_number = c("08NL071", "08NM174"),
  parameters = c(47, 5),
  end_date = Sys.Date(), # today
  start_date = Sys.Date() - lubridate::days(5) # five days ago
)

## End(Not run)

A search function for hydrometric station name or number

Description

Use this search function when you only know the partial station name or want to search.

Usage

search_stn_name(search_term, hydat_path = NULL)

search_stn_number(search_term, hydat_path = NULL)

Arguments

search_term

Only accepts one word.

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing database connection from hy_src() such that the database only needs to be opened once per user-level call.

Value

A tibble of stations that match the search_term

Examples

## Not run: 
search_stn_name("Cowichan")

search_stn_number("08HF")

## End(Not run)


Function to chose a station based on consistent arguments for hydat functions.

Description

A function to avoid duplication in HYDAT functions. This function is not intended for external use.

Usage

station_choice(hydat_con, station_number, prov_terr_state_loc)

Arguments

hydat_con

A database connection

station_number

A seven digit Water Survey of Canada station number. If this argument is omitted, the value of prov_terr_state_loc is returned.

prov_terr_state_loc

Province, state or territory. If this argument is omitted, the value of station_number is returned. See unique(allstations$prov_terr_state_loc). Will also accept CA to return only Canadian stations.


Summarize available data by station

Description

Returns a tibble with date ranges and record counts for each station, broken down by approval status (final vs provisional).

Usage

## S3 method for class 'available'
summary(object, ...)

Arguments

object

Object created by available_flows() or available_levels()

...

ignored

Value

A tibble with columns:

Examples

## Not run: 
flows <- available_flows(c("08MF005", "08MF010"))
summary(flows)

## End(Not run)


Tidy eval helpers

Description

These functions provide tidy eval-compatible ways to capture symbols (sym(), syms(), ensym()), expressions (expr(), exprs(), enexpr()), and quosures (quo(), quos(), enquo()).

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.