From b07d42d030ff760f09ef7e4e7716de8bad1a5f0a Mon Sep 17 00:00:00 2001 From: Sam Albers Date: Fri, 4 Oct 2024 13:49:16 -0700 Subject: [PATCH] use native pipe (#209) --- DESCRIPTION | 4 +- NAMESPACE | 2 - NEWS.md | 2 +- R/download.R | 6 +- R/hy.R | 10 +-- R/hy_annual_instant_peaks.R | 4 +- R/hy_annual_stats.R | 10 +-- R/hy_db.R | 4 +- R/hy_stations.R | 8 +- R/realtime.R | 4 +- R/utils-search.R | 12 +-- R/utils.R | 27 +++---- .../process_internal_data.R | 24 +++--- data-raw/HYDAT_internal_data/tinyhydat_proc.R | 20 ++--- man/hy_agency_list.Rd | 4 +- man/hy_annual_instant_peaks.Rd | 4 +- man/hy_annual_stats.Rd | 4 +- man/hy_daily.Rd | 2 +- man/hy_daily_flows.Rd | 4 +- man/hy_daily_levels.Rd | 4 +- man/hy_data_symbols.Rd | 4 +- man/hy_data_types.Rd | 4 +- man/hy_datum_list.Rd | 4 +- man/hy_monthly_flows.Rd | 4 +- man/hy_monthly_levels.Rd | 4 +- man/hy_reg_office_list.Rd | 4 +- man/hy_sed_daily_loads.Rd | 4 +- man/hy_sed_daily_suscon.Rd | 4 +- man/hy_sed_monthly_loads.Rd | 4 +- man/hy_sed_monthly_suscon.Rd | 4 +- man/hy_sed_samples.Rd | 2 +- man/hy_sed_samples_psd.Rd | 2 +- man/hy_src.Rd | 4 +- man/hy_stations.Rd | 4 +- man/hy_stn_data_coll.Rd | 4 +- man/hy_stn_data_range.Rd | 4 +- man/hy_stn_op_schedule.Rd | 4 +- man/hy_stn_regulation.Rd | 4 +- man/hy_version.Rd | 4 +- man/pull_station_number.Rd | 4 +- man/realtime_add_local_datetime.Rd | 2 +- man/realtime_daily_mean.Rd | 2 +- man/reexports.Rd | 16 ---- .../tidyhydat_intro/tidyhydat_intro.Rmd | 68 ++++++++--------- .../test_realtime_add_local_datetime.R | 6 +- tests/testthat/test_station_choice.R | 6 +- tests/testthat/test_utils.R | 4 +- vignettes/tidyhydat_an_introduction.Rmd | 16 ++-- vignettes/tidyhydat_an_introduction.Rmd.orig | 16 ++-- vignettes/tidyhydat_example_analysis.Rmd | 74 +++++++++---------- vignettes/tidyhydat_example_analysis.Rmd.orig | 74 +++++++++---------- vignettes/tidyhydat_hydat_db.Rmd | 4 +- vignettes/tidyhydat_hydat_db.Rmd.orig | 4 +- 53 files changed, 252 insertions(+), 275 deletions(-) delete mode 100644 man/reexports.Rd diff --git a/DESCRIPTION b/DESCRIPTION index a1c0558..25bfa46 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidyhydat Title: Extract and Tidy Canadian 'Hydrometric' Data -Version: 0.6.1 +Version: 0.6.1.9000 Authors@R: c(person("Sam", "Albers", email = "sam.albers@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9270-7884")), person("David", "Hutchinson", email = "david.hutchinson@canada.ca", role = "ctb"), @@ -45,4 +45,4 @@ VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE) LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index 13f0d5f..2b06b9d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,6 @@ S3method(plot,hy) S3method(plot,realtime) S3method(print,hy) S3method(print,realtime) -export("%>%") export(download_hydat) export(enexpr) export(enquo) @@ -59,7 +58,6 @@ export(search_stn_name) export(search_stn_number) export(sym) export(syms) -importFrom(dplyr,"%>%") importFrom(rlang,":=") importFrom(rlang,.data) importFrom(rlang,UQ) diff --git a/NEWS.md b/NEWS.md index c9657a1..3954ff0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# tidyhydat 0.6.2 +# tidyhydat 0.6.1.9000 - bump minimum R version to 4.0.0 - dropped httr in favour of httr2 - fix bug where `download_hydat()` fails if `tempdir()` is on a different device than `hydat_path` (@mpdavison, #192) diff --git a/R/download.R b/R/download.R index efe7b86..4b3ed3b 100644 --- a/R/download.R +++ b/R/download.R @@ -184,9 +184,9 @@ hy_check <- function(hydat_path = NULL) { invisible(lapply(have_tbls, function(x) { - tbl_rows <- dplyr::tbl(con, x) %>% - utils::head(1) %>% - dplyr::collect() %>% + tbl_rows <- dplyr::tbl(con, x) |> + utils::head(1) |> + dplyr::collect() |> nrow() if (tbl_rows == 0) { diff --git a/R/hy.R b/R/hy.R index 4d21ec5..b79fc48 100644 --- a/R/hy.R +++ b/R/hy.R @@ -361,7 +361,7 @@ hy_agency_list <- function(hydat_path = NULL) { on.exit(hy_src_disconnect(hydat_con), add = TRUE) } - agency_list <- dplyr::tbl(hydat_con, "AGENCY_LIST") %>% + agency_list <- dplyr::tbl(hydat_con, "AGENCY_LIST") |> dplyr::collect() as.hy(agency_list) @@ -389,7 +389,7 @@ hy_reg_office_list <- function(hydat_path = NULL) { on.exit(hy_src_disconnect(hydat_con), add = TRUE) } - regional_office_list <- dplyr::tbl(hydat_con, "REGIONAL_OFFICE_LIST") %>% + regional_office_list <- dplyr::tbl(hydat_con, "REGIONAL_OFFICE_LIST") |> dplyr::collect() as.hy(regional_office_list) @@ -418,7 +418,7 @@ hy_datum_list <- function(hydat_path = NULL) { on.exit(hy_src_disconnect(hydat_con), add = TRUE) } - datum_list <- dplyr::tbl(hydat_con, "DATUM_LIST") %>% + datum_list <- dplyr::tbl(hydat_con, "DATUM_LIST") |> dplyr::collect() as.hy(datum_list) @@ -448,8 +448,8 @@ hy_version <- function(hydat_path = NULL) { on.exit(hy_src_disconnect(hydat_con), add = TRUE) } - version <- dplyr::tbl(hydat_con, "VERSION") %>% - dplyr::collect() %>% + version <- dplyr::tbl(hydat_con, "VERSION") |> + dplyr::collect() |> dplyr::mutate(Date = lubridate::ymd_hms(Date)) version diff --git a/R/hy_annual_instant_peaks.R b/R/hy_annual_instant_peaks.R index 011660a..33befd6 100644 --- a/R/hy_annual_instant_peaks.R +++ b/R/hy_annual_instant_peaks.R @@ -54,8 +54,8 @@ hy_annual_instant_peaks <- function(station_number = NULL, sym_STATION_NUMBER <- sym("STATION_NUMBER") ## Data manipulations - aip <- dplyr::tbl(hydat_con, "ANNUAL_INSTANT_PEAKS") %>% - dplyr::filter(!!sym_STATION_NUMBER %in% stns) %>% + aip <- dplyr::tbl(hydat_con, "ANNUAL_INSTANT_PEAKS") |> + dplyr::filter(!!sym_STATION_NUMBER %in% stns) |> dplyr::collect() ## Add in english data type diff --git a/R/hy_annual_stats.R b/R/hy_annual_stats.R index 5bc720a..e2c466b 100644 --- a/R/hy_annual_stats.R +++ b/R/hy_annual_stats.R @@ -75,7 +75,7 @@ hy_annual_stats <- function(station_number = NULL, annual_statistics <- dplyr::filter(annual_statistics, !!sym_YEAR >= start_year & !!sym_YEAR <= end_year) } - annual_statistics <- dplyr::filter(annual_statistics, !!sym_STATION_NUMBER %in% stns) %>% + annual_statistics <- dplyr::filter(annual_statistics, !!sym_STATION_NUMBER %in% stns) |> dplyr::collect() ## TODO: Figure out how to do this in fewer steps @@ -106,10 +106,10 @@ hy_annual_stats <- function(station_number = NULL, colnames(as_max) <- gsub("MAX_", "", names(as_max)) ## bind into 1 dataframe and by year and join in the symbol - annual_statistics <- as_mean %>% - dplyr::bind_rows(as_min) %>% - dplyr::bind_rows(as_max) %>% - dplyr::arrange(YEAR) %>% + annual_statistics <- as_mean |> + dplyr::bind_rows(as_min) |> + dplyr::bind_rows(as_max) |> + dplyr::arrange(YEAR) |> dplyr::left_join(tidyhydat::hy_data_symbols, by = c("SYMBOL" = "SYMBOL_ID")) ## Format date of occurence; SuppressWarnings are justified because NA's are valid for MEAN Sum_stat diff --git a/R/hy_db.R b/R/hy_db.R index 7717ff6..af93c58 100644 --- a/R/hy_db.R +++ b/R/hy_db.R @@ -28,8 +28,8 @@ #' #' # 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") %>% +#' tbl(src, "STATIONS") |> +#' filter(PROV_TERR_STATE_LOC == "BC") |> #' collect() #' #' # close the connection to the database diff --git a/R/hy_stations.R b/R/hy_stations.R index 37bc6d1..9582d78 100644 --- a/R/hy_stations.R +++ b/R/hy_stations.R @@ -82,10 +82,10 @@ hy_stations <- function(station_number = NULL, sym_STATION_NUMBER <- sym("STATION_NUMBER") ## Create the dataframe to return - df <- dplyr::tbl(hydat_con, "STATIONS") %>% - dplyr::filter(!!sym_STATION_NUMBER %in% stns) %>% - dplyr::collect() %>% - dplyr::mutate(REGIONAL_OFFICE_ID = as.numeric(REGIONAL_OFFICE_ID)) %>% + df <- dplyr::tbl(hydat_con, "STATIONS") |> + dplyr::filter(!!sym_STATION_NUMBER %in% stns) |> + dplyr::collect() |> + dplyr::mutate(REGIONAL_OFFICE_ID = as.numeric(REGIONAL_OFFICE_ID)) |> dplyr::mutate( HYD_STATUS = dplyr::case_when( HYD_STATUS == "D" ~ "DISCONTINUED", diff --git a/R/realtime.R b/R/realtime.R index f28a8fd..2897276 100644 --- a/R/realtime.R +++ b/R/realtime.R @@ -148,7 +148,7 @@ realtime_stations <- function(prov_terr_state_loc = NULL) { #' @examples #' \dontrun{ #' -#' realtime_dd(c("08MF005", "02LA004")) %>% +#' realtime_dd(c("08MF005", "02LA004")) |> #' realtime_add_local_datetime() #' } #' @@ -188,7 +188,7 @@ realtime_add_local_datetime <- function(.data, set_tz = NULL) { #' #' @examples #' \dontrun{ -#' realtime_dd("08MF005") %>% realtime_daily_mean() +#' realtime_dd("08MF005") |> realtime_daily_mean() #' } #' #' @export diff --git a/R/utils-search.R b/R/utils-search.R index 5b754b7..183199c 100644 --- a/R/utils-search.R +++ b/R/utils-search.R @@ -25,9 +25,9 @@ search_stn_name <- function(search_term, hydat_path = NULL) { on.exit(hy_src_disconnect(hydat_con), add = TRUE) } - results <- realtime_stations() %>% - dplyr::bind_rows(suppressMessages(hy_stations(hydat_path = hydat_con))) %>% - dplyr::distinct(STATION_NUMBER, .keep_all = TRUE) %>% + results <- realtime_stations() |> + dplyr::bind_rows(suppressMessages(hy_stations(hydat_path = hydat_con))) |> + dplyr::distinct(STATION_NUMBER, .keep_all = TRUE) |> dplyr::select(STATION_NUMBER, STATION_NAME, PROV_TERR_STATE_LOC, LATITUDE, LONGITUDE) results <- results[grepl(toupper(search_term), results$STATION_NAME), ] @@ -51,9 +51,9 @@ search_stn_number <- function(search_term, hydat_path = NULL) { on.exit(hy_src_disconnect(hydat_con), add = TRUE) } - results <- realtime_stations() %>% - dplyr::bind_rows(suppressMessages(hy_stations(hydat_path = hydat_con))) %>% - dplyr::distinct(STATION_NUMBER, .keep_all = TRUE) %>% + results <- realtime_stations() |> + dplyr::bind_rows(suppressMessages(hy_stations(hydat_path = hydat_con))) |> + dplyr::distinct(STATION_NUMBER, .keep_all = TRUE) |> dplyr::select(STATION_NUMBER, STATION_NAME, PROV_TERR_STATE_LOC, LATITUDE, LONGITUDE) results <- results[grepl(toupper(search_term), results$STATION_NUMBER), ] diff --git a/R/utils.R b/R/utils.R index cf94dbd..b62b2b6 100644 --- a/R/utils.R +++ b/R/utils.R @@ -42,8 +42,8 @@ station_choice <- function(hydat_con, station_number, prov_terr_state_loc) { ## Get all stations if (is.null(station_number) && is.null(prov_terr_state_loc)) { - stns <- dplyr::tbl(hydat_con, "STATIONS") %>% - dplyr::collect() %>% + stns <- dplyr::tbl(hydat_con, "STATIONS") |> + dplyr::collect() |> dplyr::pull(STATION_NUMBER) return(stns) } @@ -63,9 +63,9 @@ station_choice <- function(hydat_con, station_number, prov_terr_state_loc) { if (any(!prov_terr_state_loc %in% stn_option) == TRUE) stop("Invalid prov_terr_state_loc value") - dplyr::tbl(hydat_con, "STATIONS") %>% - dplyr::filter(!!sym_PROV_TERR_STATE_LOC %in% prov_terr_state_loc) %>% - dplyr::collect() %>% + dplyr::tbl(hydat_con, "STATIONS") |> + dplyr::filter(!!sym_PROV_TERR_STATE_LOC %in% prov_terr_state_loc) |> + dplyr::collect() |> dplyr::pull(STATION_NUMBER) } } @@ -95,11 +95,6 @@ date_check <- function(start_date = NULL, end_date = NULL) { invisible(list(start_is_null = start_is_null, end_is_null = end_is_null)) } -#' @importFrom dplyr %>% -#' @export -dplyr::`%>%` - - ## Simple error handler #' @noRd handle_error <- function(code) { @@ -147,10 +142,10 @@ multi_param_msg <- function(data_arg, stns, params) { sym_Parameter <- sym("Parameter") - flow_stns <- data_arg %>% - dplyr::filter(!!sym_Parameter == params) %>% - dplyr::distinct(STATION_NUMBER) %>% - dplyr::arrange(STATION_NUMBER) %>% + flow_stns <- data_arg |> + dplyr::filter(!!sym_Parameter == params) |> + dplyr::distinct(STATION_NUMBER) |> + dplyr::arrange(STATION_NUMBER) |> dplyr::pull(STATION_NUMBER) good_stns <- c() @@ -225,8 +220,8 @@ tidyhydat_agent <- function(req) { #' @examples #' \dontrun{ #' -#' hy_stations(prov_terr_state_loc = "PE") %>% -#' pull_station_number() %>% +#' hy_stations(prov_terr_state_loc = "PE") |> +#' pull_station_number() |> #' hy_annual_instant_peaks() #' } #' diff --git a/data-raw/HYDAT_internal_data/process_internal_data.R b/data-raw/HYDAT_internal_data/process_internal_data.R index 148a690..48dadfb 100644 --- a/data-raw/HYDAT_internal_data/process_internal_data.R +++ b/data-raw/HYDAT_internal_data/process_internal_data.R @@ -22,14 +22,14 @@ create_olson <- function(t) { } #' A tibble of all Canadian Stations stations and their names. -allstations <- realtime_stations() %>% - mutate(HYD_STATUS = "ACTIVE", REAL_TIME = TRUE) %>% - bind_rows(hy_stations()) %>% - distinct(STATION_NUMBER, .keep_all = TRUE) %>% - select(STATION_NUMBER, STATION_NAME, PROV_TERR_STATE_LOC, HYD_STATUS, REAL_TIME, LATITUDE, LONGITUDE) %>% - mutate(station_tz = tz_lookup_coords(LATITUDE, LONGITUDE, method = "accurate")) %>% - mutate(standard_offset = map_dbl(station_tz, ~ tz_offset(.x))) %>% - mutate(OlsonName = map_chr(standard_offset, ~ create_olson(.x))) %>% +allstations <- realtime_stations() |> + mutate(HYD_STATUS = "ACTIVE", REAL_TIME = TRUE) |> + bind_rows(hy_stations()) |> + distinct(STATION_NUMBER, .keep_all = TRUE) |> + select(STATION_NUMBER, STATION_NAME, PROV_TERR_STATE_LOC, HYD_STATUS, REAL_TIME, LATITUDE, LONGITUDE) |> + mutate(station_tz = tz_lookup_coords(LATITUDE, LONGITUDE, method = "accurate")) |> + mutate(standard_offset = map_dbl(station_tz, ~ tz_offset(.x))) |> + mutate(OlsonName = map_chr(standard_offset, ~ create_olson(.x))) |> write_csv("./data-raw/HYDAT_internal_data/allstations.csv") ## Manually adding NL for now @@ -46,14 +46,14 @@ if (!all(unique(allstations$OlsonName) %in% c(OlsonNames(), "Etc/GMT+3.5"))) { hydat_con <- DBI::dbConnect(RSQLite::SQLite(), file.path(hy_dir(), "Hydat.sqlite3")) ## DATA_TYPES -hy_data_types <- tbl(hydat_con, "DATA_TYPES") %>% - collect() %>% +hy_data_types <- tbl(hydat_con, "DATA_TYPES") |> + collect() |> mutate(DATA_TYPE_FR = iconv(DATA_TYPE_FR, from = "UTF-8", to = "ASCII//TRANSLIT")) use_data(hy_data_types, overwrite = TRUE) ## DATA_SYMBOLS -hy_data_symbols <- tbl(hydat_con, "DATA_SYMBOLS") %>% - collect() %>% +hy_data_symbols <- tbl(hydat_con, "DATA_SYMBOLS") |> + collect() |> mutate(SYMBOL_FR = iconv(SYMBOL_FR, from = "UTF-8", to = "ASCII//TRANSLIT")) use_data(hy_data_symbols, overwrite = TRUE) diff --git a/data-raw/HYDAT_internal_data/tinyhydat_proc.R b/data-raw/HYDAT_internal_data/tinyhydat_proc.R index c876f47..e64cb10 100644 --- a/data-raw/HYDAT_internal_data/tinyhydat_proc.R +++ b/data-raw/HYDAT_internal_data/tinyhydat_proc.R @@ -31,26 +31,26 @@ table_vector <- c( ) ## List of tables with STATION_NUMBER INFORMATION -list_of_small_tables <- table_vector %>% - map(~ tbl(src = hydat_con, .) %>% +list_of_small_tables <- table_vector |> + map(~ tbl(src = hydat_con, .) |> filter(STATION_NUMBER %in% c( "08MF005", "08NM083", "08NE102", "05AA008", "05HD008" - )) %>% - head(2000) %>% - collect()) %>% + )) |> + head(2000) |> + collect()) |> set_names(table_vector) ## All tables without STATION_NUMBER no_stn_table_vector <- all_tables[!all_tables %in% table_vector] -list_of_no_stn_tables <- no_stn_table_vector %>% - map(~ tbl(src = hydat_con, .) %>% - head(50) %>% - collect()) %>% +list_of_no_stn_tables <- no_stn_table_vector |> + map(~ tbl(src = hydat_con, .) |> + head(50) |> + collect()) |> set_names(no_stn_table_vector) -SED_DATA_TYPES <- dplyr::tbl(hydat_con, "SED_DATA_TYPES") %>% collect() +SED_DATA_TYPES <- dplyr::tbl(hydat_con, "SED_DATA_TYPES") |> collect() DBI::dbDisconnect(hydat_con) diff --git a/man/hy_agency_list.Rd b/man/hy_agency_list.Rd index e74070a..6082fde 100644 --- a/man/hy_agency_list.Rd +++ b/man/hy_agency_list.Rd @@ -31,9 +31,9 @@ hy_agency_list() Other HYDAT functions: \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -44,8 +44,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_annual_instant_peaks.Rd b/man/hy_annual_instant_peaks.Rd index e387519..ae141e1 100644 --- a/man/hy_annual_instant_peaks.Rd +++ b/man/hy_annual_instant_peaks.Rd @@ -52,9 +52,9 @@ hy_annual_instant_peaks(prov_terr_state_loc = c("AB", "YT")) Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -65,8 +65,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_annual_stats.Rd b/man/hy_annual_stats.Rd index 2d1ffd1..fbe9643 100644 --- a/man/hy_annual_stats.Rd +++ b/man/hy_annual_stats.Rd @@ -66,9 +66,9 @@ hy_annual_stats(prov_terr_state_loc = c("AB", "SK")) Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -79,8 +79,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_daily.Rd b/man/hy_daily.Rd index c120858..e5678f1 100644 --- a/man/hy_daily.Rd +++ b/man/hy_daily.Rd @@ -68,8 +68,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_daily_flows.Rd b/man/hy_daily_flows.Rd index a78ee7f..a703234 100644 --- a/man/hy_daily_flows.Rd +++ b/man/hy_daily_flows.Rd @@ -70,8 +70,8 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, -\code{\link{hy_daily_levels}()}, \code{\link{hy_daily}()}, +\code{\link{hy_daily_levels}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -82,8 +82,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_daily_levels.Rd b/man/hy_daily_levels.Rd index 7156777..0184e27 100644 --- a/man/hy_daily_levels.Rd +++ b/man/hy_daily_levels.Rd @@ -69,8 +69,8 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, -\code{\link{hy_daily_flows}()}, \code{\link{hy_daily}()}, +\code{\link{hy_daily_flows}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -81,8 +81,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_data_symbols.Rd b/man/hy_data_symbols.Rd index 9c94027..d5fa3ac 100644 --- a/man/hy_data_symbols.Rd +++ b/man/hy_data_symbols.Rd @@ -26,9 +26,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, \code{\link{hy_monthly_flows}()}, @@ -38,8 +38,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_data_types.Rd b/man/hy_data_types.Rd index 64a98d0..0292d4c 100644 --- a/man/hy_data_types.Rd +++ b/man/hy_data_types.Rd @@ -26,9 +26,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_datum_list}()}, \code{\link{hy_monthly_flows}()}, @@ -38,8 +38,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_datum_list.Rd b/man/hy_datum_list.Rd index 17413ed..0662d5d 100644 --- a/man/hy_datum_list.Rd +++ b/man/hy_datum_list.Rd @@ -32,9 +32,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_monthly_flows}()}, @@ -44,8 +44,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_monthly_flows.Rd b/man/hy_monthly_flows.Rd index e437088..305df66 100644 --- a/man/hy_monthly_flows.Rd +++ b/man/hy_monthly_flows.Rd @@ -69,9 +69,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -81,8 +81,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_monthly_levels.Rd b/man/hy_monthly_levels.Rd index 50900b8..4897152 100644 --- a/man/hy_monthly_levels.Rd +++ b/man/hy_monthly_levels.Rd @@ -68,9 +68,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -80,8 +80,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_reg_office_list.Rd b/man/hy_reg_office_list.Rd index ca74661..4f55bed 100644 --- a/man/hy_reg_office_list.Rd +++ b/man/hy_reg_office_list.Rd @@ -32,9 +32,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -44,8 +44,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_sed_daily_loads.Rd b/man/hy_sed_daily_loads.Rd index 976afe6..fd92cd7 100644 --- a/man/hy_sed_daily_loads.Rd +++ b/man/hy_sed_daily_loads.Rd @@ -59,9 +59,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -71,8 +71,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_sed_daily_suscon.Rd b/man/hy_sed_daily_suscon.Rd index 54dd596..2fefedf 100644 --- a/man/hy_sed_daily_suscon.Rd +++ b/man/hy_sed_daily_suscon.Rd @@ -64,9 +64,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -76,8 +76,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_loads}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_sed_monthly_loads.Rd b/man/hy_sed_monthly_loads.Rd index 45455be..4f1c1e4 100644 --- a/man/hy_sed_monthly_loads.Rd +++ b/man/hy_sed_monthly_loads.Rd @@ -64,9 +64,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -76,8 +76,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_loads}()}, \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_sed_monthly_suscon.Rd b/man/hy_sed_monthly_suscon.Rd index ee8ca42..b9cc20e 100644 --- a/man/hy_sed_monthly_suscon.Rd +++ b/man/hy_sed_monthly_suscon.Rd @@ -63,9 +63,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -75,8 +75,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_loads}()}, \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_sed_samples.Rd b/man/hy_sed_samples.Rd index c866395..fc992af 100644 --- a/man/hy_sed_samples.Rd +++ b/man/hy_sed_samples.Rd @@ -72,9 +72,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, diff --git a/man/hy_sed_samples_psd.Rd b/man/hy_sed_samples_psd.Rd index b2cacf4..385e6ea 100644 --- a/man/hy_sed_samples_psd.Rd +++ b/man/hy_sed_samples_psd.Rd @@ -60,9 +60,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, diff --git a/man/hy_src.Rd b/man/hy_src.Rd index 3b8cc00..82f5cd6 100644 --- a/man/hy_src.Rd +++ b/man/hy_src.Rd @@ -39,8 +39,8 @@ 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") \%>\% +tbl(src, "STATIONS") |> + filter(PROV_TERR_STATE_LOC == "BC") |> collect() # close the connection to the database diff --git a/man/hy_stations.Rd b/man/hy_stations.Rd index 004dbed..dabcdf7 100644 --- a/man/hy_stations.Rd +++ b/man/hy_stations.Rd @@ -76,9 +76,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -89,8 +89,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, \code{\link{hy_stn_op_schedule}()}, diff --git a/man/hy_stn_data_coll.Rd b/man/hy_stn_data_coll.Rd index 5707a9e..fb976b2 100644 --- a/man/hy_stn_data_coll.Rd +++ b/man/hy_stn_data_coll.Rd @@ -55,9 +55,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -68,8 +68,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_range}()}, \code{\link{hy_stn_op_schedule}()}, diff --git a/man/hy_stn_data_range.Rd b/man/hy_stn_data_range.Rd index 56a3cb8..2d612e1 100644 --- a/man/hy_stn_data_range.Rd +++ b/man/hy_stn_data_range.Rd @@ -53,9 +53,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -66,8 +66,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_op_schedule}()}, diff --git a/man/hy_stn_op_schedule.Rd b/man/hy_stn_op_schedule.Rd index d59b92b..725b4db 100644 --- a/man/hy_stn_op_schedule.Rd +++ b/man/hy_stn_op_schedule.Rd @@ -52,9 +52,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -65,8 +65,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_stn_regulation.Rd b/man/hy_stn_regulation.Rd index d7c49c2..4ec43cc 100644 --- a/man/hy_stn_regulation.Rd +++ b/man/hy_stn_regulation.Rd @@ -57,9 +57,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -70,8 +70,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/hy_version.Rd b/man/hy_version.Rd index af28452..65d9a38 100644 --- a/man/hy_version.Rd +++ b/man/hy_version.Rd @@ -32,9 +32,9 @@ Other HYDAT functions: \code{\link{hy_agency_list}()}, \code{\link{hy_annual_instant_peaks}()}, \code{\link{hy_annual_stats}()}, +\code{\link{hy_daily}()}, \code{\link{hy_daily_flows}()}, \code{\link{hy_daily_levels}()}, -\code{\link{hy_daily}()}, \code{\link{hy_data_symbols}}, \code{\link{hy_data_types}}, \code{\link{hy_datum_list}()}, @@ -45,8 +45,8 @@ Other HYDAT functions: \code{\link{hy_sed_daily_suscon}()}, \code{\link{hy_sed_monthly_loads}()}, \code{\link{hy_sed_monthly_suscon}()}, -\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_sed_samples}()}, +\code{\link{hy_sed_samples_psd}()}, \code{\link{hy_stations}()}, \code{\link{hy_stn_data_coll}()}, \code{\link{hy_stn_data_range}()}, diff --git a/man/pull_station_number.Rd b/man/pull_station_number.Rd index 1a43224..1456ec3 100644 --- a/man/pull_station_number.Rd +++ b/man/pull_station_number.Rd @@ -20,8 +20,8 @@ This can be used with \code{realtime_} and \code{hy_} functions. \examples{ \dontrun{ -hy_stations(prov_terr_state_loc = "PE") \%>\% - pull_station_number() \%>\% +hy_stations(prov_terr_state_loc = "PE") |> + pull_station_number() |> hy_annual_instant_peaks() } diff --git a/man/realtime_add_local_datetime.Rd b/man/realtime_add_local_datetime.Rd index 66b8002..1e3b9e2 100644 --- a/man/realtime_add_local_datetime.Rd +++ b/man/realtime_add_local_datetime.Rd @@ -24,7 +24,7 @@ useful when all stations exist within the same timezone. \examples{ \dontrun{ -realtime_dd(c("08MF005", "02LA004")) \%>\% +realtime_dd(c("08MF005", "02LA004")) |> realtime_add_local_datetime() } diff --git a/man/realtime_daily_mean.Rd b/man/realtime_daily_mean.Rd index 4ced5ee..2933e37 100644 --- a/man/realtime_daily_mean.Rd +++ b/man/realtime_daily_mean.Rd @@ -17,7 +17,7 @@ data to daily means. } \examples{ \dontrun{ -realtime_dd("08MF005") \%>\% realtime_daily_mean() +realtime_dd("08MF005") |> realtime_daily_mean() } } diff --git a/man/reexports.Rd b/man/reexports.Rd deleted file mode 100644 index bd44fd4..0000000 --- a/man/reexports.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\docType{import} -\name{reexports} -\alias{reexports} -\alias{\%>\%} -\title{Objects exported from other packages} -\keyword{internal} -\description{ -These objects are imported from other packages. Follow the links -below to see their documentation. - -\describe{ - \item{dplyr}{\code{\link[dplyr:reexports]{\%>\%}}} -}} - diff --git a/presentations/tidyhydat_intro/tidyhydat_intro.Rmd b/presentations/tidyhydat_intro/tidyhydat_intro.Rmd index 573335e..a2510ba 100644 --- a/presentations/tidyhydat_intro/tidyhydat_intro.Rmd +++ b/presentations/tidyhydat_intro/tidyhydat_intro.Rmd @@ -238,18 +238,18 @@ class:basic ## hydat::Water Survey of Canada Network ```{r out.width='100%', fig.height=6, eval=TRUE, message=FALSE} -stns <- hy_stations() %>% +stns <- hy_stations() |> filter(HYD_STATUS == "ACTIVE") st_as_sf(stns, coords = c("LONGITUDE","LATITUDE"), crs = 4326, - agr= "constant") %>% + agr= "constant") |> mapview(zcol = "STATION_NAME", legend = FALSE, map.types = "Esri.WorldImagery", cex = 4, popup = popupTable(., zcol = c("STATION_NUMBER", "STATION_NAME", "PROV_TERR_STATE_LOC"))) -#leaflet(data = stns) %>% -# addTiles() %>% -# addMarkers(~LONGITUDE, ~LATITUDE, label=~as.character(STATION_NAME), clusterOptions = markerClusterOptions()) %>% # +#leaflet(data = stns) |> +# addTiles() |> +# addMarkers(~LONGITUDE, ~LATITUDE, label=~as.character(STATION_NAME), clusterOptions = markerClusterOptions()) |> # # setView(-96, 63, zoom = 3) ``` @@ -275,8 +275,8 @@ mapview(zcol = "STATION_NAME", legend = FALSE, map.types = "Esri.WorldImagery", ## tidy::untidy data ```{r, echo = FALSE} src <- hy_src() -tbl(src, "DLY_FLOWS") %>% - filter(STATION_NUMBER == "08MF005") %>% +tbl(src, "DLY_FLOWS") |> + filter(STATION_NUMBER == "08MF005") |> select(-contains("_SYMBOL"), ) ``` @@ -337,9 +337,9 @@ class: basiclh, center ```{r, eval=TRUE, echo=FALSE, message=FALSE} stns_tbl <- hy_stations(c("08MF005","09CD001","05KJ001","02KF005"))[,c("STATION_NUMBER", "STATION_NAME")] -x <- stns_tbl %>% - rename(`Station Name`=STATION_NAME, `Station Number`=STATION_NUMBER) %>% - knitr::kable(format = 'html') %>% +x <- stns_tbl |> + rename(`Station Name`=STATION_NAME, `Station Number`=STATION_NUMBER) |> + knitr::kable(format = 'html') |> kableExtra::kable_styling(bootstrap_options = c("striped", "hover")) gsub(".*", "", x) ``` @@ -350,7 +350,7 @@ stns <- hy_stations(stns_tbl$STATION_NUMBER) st_as_sf(stns, coords = c("LONGITUDE","LATITUDE"), crs = 4326, - agr= "constant") %>% + agr= "constant") |> mapview(zcol = "STATION_NAME", legend = FALSE, cex = 6, popup = popupTable(., zcol = c("STATION_NUMBER", "STATION_NAME", "PROV_TERR_STATE_LOC"))) ``` @@ -368,18 +368,18 @@ flows_data ## Build the analysis ```{r, echo = TRUE} -flows_data %>% +flows_data |> spread(key = STATION_NUMBER, value = Value) #<< ``` -### `%>%`: "then" +### `|>`: "then" ### `spread`: function --- ## Build the analysis ```{r, echo = TRUE} -flows_data %>% - spread(key = STATION_NUMBER, value = Value) %>% +flows_data |> + spread(key = STATION_NUMBER, value = Value) |> select(-Date, -Symbol, -Parameter) #<< ``` @@ -388,9 +388,9 @@ flows_data %>% ## Build the analysis ```{r, echo = TRUE} -flows_data %>% - spread(key = STATION_NUMBER, value = Value) %>% - select(-Date, -Symbol, -Parameter) %>% +flows_data |> + spread(key = STATION_NUMBER, value = Value) |> + select(-Date, -Symbol, -Parameter) |> correlate() #<< ``` @@ -399,10 +399,10 @@ flows_data %>% ## Build the analysis ```{r, echo = TRUE} -flows_data %>% - spread(key = STATION_NUMBER, value = Value) %>% - select(-Date, -Symbol, -Parameter) %>% - correlate() %>% +flows_data |> + spread(key = STATION_NUMBER, value = Value) |> + select(-Date, -Symbol, -Parameter) |> + correlate() |> stretch() #<< ``` @@ -412,12 +412,12 @@ flows_data %>% ## Scalable ```{r scalable1, echo = FALSE, message=FALSE, fig.width = 10, fig.height=6} -stns <- hy_stations(prov_terr_state_loc = "NU") %>% +stns <- hy_stations(prov_terr_state_loc = "NU") |> filter(HYD_STATUS == "ACTIVE") st_as_sf(stns, coords = c("LONGITUDE","LATITUDE"), crs = 4326, - agr= "constant") %>% + agr= "constant") |> mapview(zcol = "STATION_NAME", legend = FALSE, popup = popupTable(., zcol = c("STATION_NUMBER", "STATION_NAME", "PROV_TERR_STATE_LOC", "HYD_STATUS"))) ``` @@ -426,7 +426,7 @@ mapview(zcol = "STATION_NAME", legend = FALSE, ## Scalable ```{r scalable2, echo = TRUE, message=FALSE} -stns <- hy_stations(prov_terr_state_loc = "NU") %>% +stns <- hy_stations(prov_terr_state_loc = "NU") |> filter(HYD_STATUS == "ACTIVE") nu_flows <- hy_daily_flows(station_number = stns$STATION_NUMBER) @@ -437,10 +437,10 @@ nu_flows ## Scalable ```{r scalable3, echo = TRUE, message=FALSE} -nu_flows %>% #<< - spread(STATION_NUMBER, Value) %>% - select(-Date, -Symbol, -Parameter) %>% - correlate() %>% +nu_flows |> #<< + spread(STATION_NUMBER, Value) |> + select(-Date, -Symbol, -Parameter) |> + correlate() |> stretch() ``` @@ -484,13 +484,13 @@ realtime_plot("08MF005", Parameter = "Flow") --- ## What else is available in R? ```{r, warning=FALSE, message=FALSE, echo=TRUE} -raw_stns <- hy_stations() %>% +raw_stns <- hy_stations() |> select(STATION_NUMBER:PROV_TERR_STATE_LOC, DRAINAGE_AREA_GROSS) -mad_long_avg <- hy_annual_stats(raw_stns$STATION_NUMBER) %>% - filter(Sum_stat == "MEAN", Parameter == "Flow") %>% - group_by(STATION_NUMBER) %>% - summarise(Value = mean(Value, na.rm = TRUE)) %>% +mad_long_avg <- hy_annual_stats(raw_stns$STATION_NUMBER) |> + filter(Sum_stat == "MEAN", Parameter == "Flow") |> + group_by(STATION_NUMBER) |> + summarise(Value = mean(Value, na.rm = TRUE)) |> right_join(raw_stns) mad_long_avg #<< ``` diff --git a/tests/testthat/test_realtime_add_local_datetime.R b/tests/testthat/test_realtime_add_local_datetime.R index f1dd494..b4dd52f 100644 --- a/tests/testthat/test_realtime_add_local_datetime.R +++ b/tests/testthat/test_realtime_add_local_datetime.R @@ -1,7 +1,7 @@ test_that("realtime_add_local_datetime add applies correct timezone", { skip_on_cran() skip_if_net_down() - col_added <- realtime_dd("08MF005") %>% realtime_add_local_datetime() + col_added <- realtime_dd("08MF005") |> realtime_add_local_datetime() expect_equal(lubridate::tz(col_added$local_datetime), unique(col_added$station_tz)) }) @@ -9,7 +9,7 @@ test_that("realtime_add_local_datetime add applies correct timezone", { test_that("realtime_add_local_datetime add applies first timezone when multiple timezones exist and generates a warning", { skip_on_cran() skip_if_net_down() - expect_warning(col_added <- realtime_dd(c("08MF005", "02LA004", "02AB006")) %>% realtime_add_local_datetime()) + expect_warning(col_added <- realtime_dd(c("08MF005", "02LA004", "02AB006")) |> realtime_add_local_datetime()) expect_equal(lubridate::tz(col_added$local_datetime), "America/Toronto") }) @@ -17,7 +17,7 @@ test_that("realtime_add_local_datetime add applies first timezone when multiple test_that("when set_tz is supplied, it is respected", { skip_on_cran() skip_if_net_down() - expect_warning(col_added <- realtime_dd(c("08MF005", "02LA004")) %>% realtime_add_local_datetime(set_tz = "America/Moncton")) + expect_warning(col_added <- realtime_dd(c("08MF005", "02LA004")) |> realtime_add_local_datetime(set_tz = "America/Moncton")) expect_equal(lubridate::tz(col_added$local_datetime), unique(col_added$tz_used)) expect_equal(lubridate::tz(col_added$local_datetime), "America/Moncton") expect_equal(unique(col_added$tz_used), "America/Moncton") diff --git a/tests/testthat/test_station_choice.R b/tests/testthat/test_station_choice.R index 0d762a1..1cd49b1 100644 --- a/tests/testthat/test_station_choice.R +++ b/tests/testthat/test_station_choice.R @@ -13,9 +13,9 @@ test_that("Test that all stations are outputted when just a province is supplied ## Read in database hydat_con <- DBI::dbConnect(RSQLite::SQLite(), hydat_path) ## All BC stations in test db - dplyr::tbl(hydat_con, "STATIONS") %>% - dplyr::filter(PROV_TERR_STATE_LOC == "BC") %>% - dplyr::collect() %>% + dplyr::tbl(hydat_con, "STATIONS") |> + dplyr::filter(PROV_TERR_STATE_LOC == "BC") |> + dplyr::collect() |> dplyr::pull(STATION_NUMBER) -> stns on.exit(DBI::dbDisconnect(hydat_con), add = TRUE) stns_out <- tidyhydat:::station_choice(hydat_con, station_number = NULL, prov_terr_state_loc = "BC") diff --git a/tests/testthat/test_utils.R b/tests/testthat/test_utils.R index 5e929c1..323c9cb 100644 --- a/tests/testthat/test_utils.R +++ b/tests/testthat/test_utils.R @@ -35,13 +35,13 @@ test_that("downloading hydat fails behind a proxy server with informative error test_that("pull_station_number fails when a dataframe doesn't contain a STATION_NUMBER column", { data(iris) - expect_error(iris %>% pull_station_number()) + expect_error(iris |> pull_station_number()) }) test_that("pull_station_number grabs station number successfully", { stns <- c("08NM083", "08NE102") - pulled_stns <- hy_annual_stats(stns, hydat_path = hy_test_db()) %>% pull_station_number() + pulled_stns <- hy_annual_stats(stns, hydat_path = hy_test_db()) |> pull_station_number() expect_identical(stns, unique(pulled_stns)) }) diff --git a/vignettes/tidyhydat_an_introduction.Rmd b/vignettes/tidyhydat_an_introduction.Rmd index 54ad858..6ea68d8 100644 --- a/vignettes/tidyhydat_an_introduction.Rmd +++ b/vignettes/tidyhydat_an_introduction.Rmd @@ -70,9 +70,9 @@ Another method is to use `hy_stations()` to generate your vector which is then g ```r -PEI_stns <- hy_stations() %>% - filter(HYD_STATUS == "ACTIVE") %>% - filter(PROV_TERR_STATE_LOC == "PE") %>% +PEI_stns <- hy_stations() |> + filter(HYD_STATUS == "ACTIVE") |> + filter(PROV_TERR_STATE_LOC == "PE") |> pull_station_number() PEI_stns @@ -115,8 +115,8 @@ hy_daily_flows(station_number = PEI_stns) We can also merge our station choice and data extraction into one unified pipe which accomplishes a single goal. For example if for some reason we wanted all the stations in Canada that had the name "Canada" in them we unify that selection and data extraction process into a single pipe: ```r -search_stn_name("canada") %>% - pull_station_number() %>% +search_stn_name("canada") |> + pull_station_number() |> hy_daily_flows() ``` @@ -238,11 +238,11 @@ Sometimes it is required to make use of information from two tables from HYDAT. ```r stns <- c("08NH130", "08NH005") -runoff_data <- hy_daily_flows(station_number = stns, start_date = "2000-01-01") %>% +runoff_data <- hy_daily_flows(station_number = stns, start_date = "2000-01-01") |> left_join( - hy_stations(station_number = stns) %>% + hy_stations(station_number = stns) |> select(STATION_NUMBER, STATION_NAME, DRAINAGE_AREA_GROSS), - by = "STATION_NUMBER") %>% + by = "STATION_NUMBER") |> ## conversion to mm/d mutate(runoff = Value / DRAINAGE_AREA_GROSS * 86400 / 1e6 * 1e3) diff --git a/vignettes/tidyhydat_an_introduction.Rmd.orig b/vignettes/tidyhydat_an_introduction.Rmd.orig index 25fc9c8..66f140e 100644 --- a/vignettes/tidyhydat_an_introduction.Rmd.orig +++ b/vignettes/tidyhydat_an_introduction.Rmd.orig @@ -47,9 +47,9 @@ hy_daily_flows(station_number = "08LA001") Another method is to use `hy_stations()` to generate your vector which is then given the `station_number` argument. For example, we could take a subset for only those active stations within Prince Edward Island (Province code:PE) and then create vector for `hy_daily_flows()`: ```{r example2, warning=FALSE} -PEI_stns <- hy_stations() %>% - filter(HYD_STATUS == "ACTIVE") %>% - filter(PROV_TERR_STATE_LOC == "PE") %>% +PEI_stns <- hy_stations() |> + filter(HYD_STATUS == "ACTIVE") |> + filter(PROV_TERR_STATE_LOC == "PE") |> pull_station_number() PEI_stns @@ -59,8 +59,8 @@ hy_daily_flows(station_number = PEI_stns) We can also merge our station choice and data extraction into one unified pipe which accomplishes a single goal. For example if for some reason we wanted all the stations in Canada that had the name "Canada" in them we unify that selection and data extraction process into a single pipe: ```{r, example3} -search_stn_name("canada") %>% - pull_station_number() %>% +search_stn_name("canada") |> + pull_station_number() |> hy_daily_flows() ``` @@ -115,11 +115,11 @@ search_stn_number("08MF") Sometimes it is required to make use of information from two tables from HYDAT. In some cases, we need to combine the information into one table using a common column. Here we will illustrate calculating runoff by combining the `hy_stations` tables with the `hy_daily_flows` table by the `STATION_NUMBER` column: ```{r} stns <- c("08NH130", "08NH005") -runoff_data <- hy_daily_flows(station_number = stns, start_date = "2000-01-01") %>% +runoff_data <- hy_daily_flows(station_number = stns, start_date = "2000-01-01") |> left_join( - hy_stations(station_number = stns) %>% + hy_stations(station_number = stns) |> select(STATION_NUMBER, STATION_NAME, DRAINAGE_AREA_GROSS), - by = "STATION_NUMBER") %>% + by = "STATION_NUMBER") |> ## conversion to mm/d mutate(runoff = Value / DRAINAGE_AREA_GROSS * 86400 / 1e6 * 1e3) diff --git a/vignettes/tidyhydat_example_analysis.Rmd b/vignettes/tidyhydat_example_analysis.Rmd index 0d7086e..926cb30 100644 --- a/vignettes/tidyhydat_example_analysis.Rmd +++ b/vignettes/tidyhydat_example_analysis.Rmd @@ -48,9 +48,9 @@ You can see where the database was downloaded by running `hy_dir()`. This should ```r -longest_record_data <- hy_stn_data_range() %>% - filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) %>% - pull_station_number() %>% +longest_record_data <- hy_stn_data_range() |> + filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) |> + pull_station_number() |> hy_daily_flows() ``` Let's break this down line by line to understand how `tidyhydat` uses tidy tools. First we are interested in getting data on record length: @@ -81,10 +81,10 @@ hy_stn_data_range() ## # ℹ 12,115 more rows ## # ℹ 1 more variable: RECORD_LENGTH ``` -Our objective here is to filter from this data for the station that has the longest record of flow (`DATA_TYPE == "Q"`). You'll also notice this symbol `%>%` which in R is called a [pipe](https://magrittr.tidyverse.org/reference/pipe.html). In code, read it as the word *then*. So for the data_range data we want to grab the data *then* filter it by flow ("Q") in `DATA_TYPE` and then by the maximum value of `RECORD_LENGTH`: +Our objective here is to filter from this data for the station that has the longest record of flow (`DATA_TYPE == "Q"`). You'll also notice this symbol `|>` which in R is called a [pipe](https://magrittr.tidyverse.org/reference/pipe.html). In code, read it as the word *then*. So for the data_range data we want to grab the data *then* filter it by flow ("Q") in `DATA_TYPE` and then by the maximum value of `RECORD_LENGTH`: ```r -hy_stn_data_range() %>% +hy_stn_data_range() |> filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) ``` @@ -103,8 +103,8 @@ hy_stn_data_range() %>% *then* pull the `STATION_NUMBER` that has the longest record: ```r -hy_stn_data_range() %>% - filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) %>% +hy_stn_data_range() |> + filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) |> pull_station_number() ``` @@ -114,16 +114,16 @@ hy_stn_data_range() %>% *then* feed that number to `hy_daily_flows()` ```r -longest_record_data <- hy_stn_data_range() %>% - filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) %>% - pull_station_number() %>% +longest_record_data <- hy_stn_data_range() |> + filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) |> + pull_station_number() |> hy_daily_flows() ``` The result of this collection of simple functions is that we've extracted data the entire daily flow dataset (from 1860-2016) from station `02HA003`.If we wanted more information on this station we could query other tables in HYDAT for more information. The `hy_stations()` function is very useful and outputs considerable metadata on a given station (converted here to a list for viewing purposes): ```r -hy_stations(station_number = unique(longest_record_data$STATION_NUMBER)) %>% +hy_stations(station_number = unique(longest_record_data$STATION_NUMBER)) |> as.list() ``` @@ -182,7 +182,7 @@ We now know that this station is actually *NIAGARA RIVER AT QUEENSTON* in Ontari ```r -longest_record_data %>% +longest_record_data |> ggplot(aes(x = Date, y = Value)) + geom_line(alpha = 0.5) + geom_point(size = 0.25) + @@ -196,9 +196,9 @@ You can see very clearly where continuous monitoring was established. However, t ```r -longest_record_data %>% - mutate(dayofyear = yday(Date), Year = year(Date)) %>% - mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) %>% ## leap year as placeholder +longest_record_data |> + mutate(dayofyear = yday(Date), Year = year(Date)) |> + mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) |> ## leap year as placeholder ggplot(aes(x = dayofyear_formatted, y = Value, colour = Year)) + geom_line() + scale_x_date(date_labels = "%b %d") + @@ -211,9 +211,9 @@ This still is not a very useful plot mostly because our colour range still doesn ```r -longest_record_data %>% - mutate(dayofyear = yday(Date), Year = year(Date)) %>% - mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) %>% +longest_record_data |> + mutate(dayofyear = yday(Date), Year = year(Date)) |> + mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) |> ggplot(aes(x = dayofyear_formatted, y = Year, fill = Value)) + geom_tile() + scale_x_date(date_labels = "%b") + @@ -245,29 +245,29 @@ The pipe below finds the active station that has realtime data in the [Reference ```r -nunavut_stn_flows <- hy_stations() %>% - filter(HYD_STATUS == "ACTIVE") %>% - filter(REAL_TIME == TRUE) %>% - filter(RHBN == TRUE) %>% - filter(PROV_TERR_STATE_LOC == "NU") %>% - pull_station_number() %>% - hy_stn_data_range() %>% - filter(DATA_TYPE == "Q") %>% - filter(RECORD_LENGTH == max(RECORD_LENGTH)) %>% - pull_station_number() %>% +nunavut_stn_flows <- hy_stations() |> + filter(HYD_STATUS == "ACTIVE") |> + filter(REAL_TIME == TRUE) |> + filter(RHBN == TRUE) |> + filter(PROV_TERR_STATE_LOC == "NU") |> + pull_station_number() |> + hy_stn_data_range() |> + filter(DATA_TYPE == "Q") |> + filter(RECORD_LENGTH == max(RECORD_LENGTH)) |> + pull_station_number() |> hy_daily_flows() ``` We can now evaluate the historical distribution of data collection to put some real time data into historical context. First we need to calculate where an individual observation is distributed against all other observations on that day for every day. The `prctile` column tells us what percentage of values on that same day over the entire data record fall above and below the observations on that row. We are restricting our analysis to the last thirty days from when this vignette was last compiled. The `ecdf()` function creates an equation to calculate percentiles based on the `Value` column (i.e discharge) then takes each individual observation of `Value` and calculates the percentile. ```r -pct_flow <- nunavut_stn_flows %>% - mutate(dayofyear = yday(Date), Year = year(Date)) %>% +pct_flow <- nunavut_stn_flows |> + mutate(dayofyear = yday(Date), Year = year(Date)) |> filter(dayofyear %in% yday(seq.Date(from = (Sys.Date()-30), - to = Sys.Date(), by = "day"))) %>% - group_by(dayofyear) %>% - mutate(prctile = ecdf(Value)(Value)) %>% - mutate(Date_no_year = dmy(paste0(day(Date),"-",month(Date),"-",year(Sys.Date())))) %>% + to = Sys.Date(), by = "day"))) |> + group_by(dayofyear) |> + mutate(prctile = ecdf(Value)(Value)) |> + mutate(Date_no_year = dmy(paste0(day(Date),"-",month(Date),"-",year(Sys.Date())))) |> ungroup() ``` @@ -275,9 +275,9 @@ To collect real time data, we can use the `realtime_dd()` function in `tidyhydat ```r -nunavut_realtime <- realtime_dd(unique(nunavut_stn_flows$STATION_NUMBER)) %>% - mutate(Date_day = as.Date(Date)) %>% - group_by(Date_day) %>% +nunavut_realtime <- realtime_dd(unique(nunavut_stn_flows$STATION_NUMBER)) |> + mutate(Date_day = as.Date(Date)) |> + group_by(Date_day) |> summarise(Value = mean(Value, na.rm = TRUE), .groups = "drop") ``` diff --git a/vignettes/tidyhydat_example_analysis.Rmd.orig b/vignettes/tidyhydat_example_analysis.Rmd.orig index bb438b5..28ebf93 100644 --- a/vignettes/tidyhydat_example_analysis.Rmd.orig +++ b/vignettes/tidyhydat_example_analysis.Rmd.orig @@ -51,37 +51,37 @@ download_hydat() You can see where the database was downloaded by running `hy_dir()`. This should be the only instance where you will need to interact directly with HYDAT. Each `tidyhydat` function prefixed with `hy` will automatically know where to look for HYDAT saving you the trouble. When using `tidyhydat`, often your first task is to find the station(s) that you are interested in. Because we are interested in the longest record we can extract that information with `hy_stn_data_range()` and then feed that information to `hy_daily_flows()` like this: ```{r, eval= FALSE, warning=FALSE, message=FALSE} -longest_record_data <- hy_stn_data_range() %>% - filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) %>% - pull_station_number() %>% +longest_record_data <- hy_stn_data_range() |> + filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) |> + pull_station_number() |> hy_daily_flows() ``` Let's break this down line by line to understand how `tidyhydat` uses tidy tools. First we are interested in getting data on record length: ```{r data_range} hy_stn_data_range() ``` -Our objective here is to filter from this data for the station that has the longest record of flow (`DATA_TYPE == "Q"`). You'll also notice this symbol `%>%` which in R is called a [pipe](https://magrittr.tidyverse.org/reference/pipe.html). In code, read it as the word *then*. So for the data_range data we want to grab the data *then* filter it by flow ("Q") in `DATA_TYPE` and then by the maximum value of `RECORD_LENGTH`: +Our objective here is to filter from this data for the station that has the longest record of flow (`DATA_TYPE == "Q"`). You'll also notice this symbol `|>` which in R is called a [pipe](https://magrittr.tidyverse.org/reference/pipe.html). In code, read it as the word *then*. So for the data_range data we want to grab the data *then* filter it by flow ("Q") in `DATA_TYPE` and then by the maximum value of `RECORD_LENGTH`: ```{r filter} -hy_stn_data_range() %>% +hy_stn_data_range() |> filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) ``` *then* pull the `STATION_NUMBER` that has the longest record: ```{r pull} -hy_stn_data_range() %>% - filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) %>% +hy_stn_data_range() |> + filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) |> pull_station_number() ``` *then* feed that number to `hy_daily_flows()` ```{r, full1} -longest_record_data <- hy_stn_data_range() %>% - filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) %>% - pull_station_number() %>% +longest_record_data <- hy_stn_data_range() |> + filter(DATA_TYPE == "Q", RECORD_LENGTH == max(RECORD_LENGTH)) |> + pull_station_number() |> hy_daily_flows() ``` The result of this collection of simple functions is that we've extracted data the entire daily flow dataset (from 1860-2016) from station `02HA003`.If we wanted more information on this station we could query other tables in HYDAT for more information. The `hy_stations()` function is very useful and outputs considerable metadata on a given station (converted here to a list for viewing purposes): ```{r hy_stns} -hy_stations(station_number = unique(longest_record_data$STATION_NUMBER)) %>% +hy_stations(station_number = unique(longest_record_data$STATION_NUMBER)) |> as.list() ``` @@ -89,7 +89,7 @@ hy_stations(station_number = unique(longest_record_data$STATION_NUMBER)) %>% We now know that this station is actually *NIAGARA RIVER AT QUEENSTON* in Ontario and has an upstream drainage basin area of 686,000 square kilometres. As a first step toward visualization, let's simply plot the time series for the entire record with a smoother added: ```{r old_rec} -longest_record_data %>% +longest_record_data |> ggplot(aes(x = Date, y = Value)) + geom_line(alpha = 0.5) + geom_point(size = 0.25) + @@ -100,9 +100,9 @@ longest_record_data %>% You can see very clearly where continuous monitoring was established. However, this type of plot obscures much of the data that we are interested in. We could plot all the years on the same axis and separate year by line colour. That requires a little bit of manipulation ahead of plotting using both `dplyr` and `lubridate`. Remember you can run a pipe adding one line at a time and comparing the outputs to get a sense of what each step is doing: ```{r old_rec_yr} -longest_record_data %>% - mutate(dayofyear = yday(Date), Year = year(Date)) %>% - mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) %>% ## leap year as placeholder +longest_record_data |> + mutate(dayofyear = yday(Date), Year = year(Date)) |> + mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) |> ## leap year as placeholder ggplot(aes(x = dayofyear_formatted, y = Value, colour = Year)) + geom_line() + scale_x_date(date_labels = "%b %d") + @@ -112,9 +112,9 @@ longest_record_data %>% This still is not a very useful plot mostly because our colour range still doesn't resolve year very well and any intra-annual is not visible with this plot. Consider, for example, if rather than a line plot we use a tile plot and modified our colour scale to include more colours: ```{r tile_plt} -longest_record_data %>% - mutate(dayofyear = yday(Date), Year = year(Date)) %>% - mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) %>% +longest_record_data |> + mutate(dayofyear = yday(Date), Year = year(Date)) |> + mutate(dayofyear_formatted = as.Date(dayofyear - 1, origin = "2016-01-01")) |> ggplot(aes(x = dayofyear_formatted, y = Year, fill = Value)) + geom_tile() + scale_x_date(date_labels = "%b") + @@ -142,37 +142,37 @@ library(lubridate) The pipe below finds the active station that has realtime data in the [Reference Hydrometric Basin Network](https://www.canada.ca/en/environment-climate-change/services/water-overview/quantity/monitoring/survey/data-products-services/reference-hydrometric-basin-network.html) (RHBN) in the territory of Nunavut that has the longest record then grabs all the daily flow information: ```{r} -nunavut_stn_flows <- hy_stations() %>% - filter(HYD_STATUS == "ACTIVE") %>% - filter(REAL_TIME == TRUE) %>% - filter(RHBN == TRUE) %>% - filter(PROV_TERR_STATE_LOC == "NU") %>% - pull_station_number() %>% - hy_stn_data_range() %>% - filter(DATA_TYPE == "Q") %>% - filter(RECORD_LENGTH == max(RECORD_LENGTH)) %>% - pull_station_number() %>% +nunavut_stn_flows <- hy_stations() |> + filter(HYD_STATUS == "ACTIVE") |> + filter(REAL_TIME == TRUE) |> + filter(RHBN == TRUE) |> + filter(PROV_TERR_STATE_LOC == "NU") |> + pull_station_number() |> + hy_stn_data_range() |> + filter(DATA_TYPE == "Q") |> + filter(RECORD_LENGTH == max(RECORD_LENGTH)) |> + pull_station_number() |> hy_daily_flows() ``` We can now evaluate the historical distribution of data collection to put some real time data into historical context. First we need to calculate where an individual observation is distributed against all other observations on that day for every day. The `prctile` column tells us what percentage of values on that same day over the entire data record fall above and below the observations on that row. We are restricting our analysis to the last thirty days from when this vignette was last compiled. The `ecdf()` function creates an equation to calculate percentiles based on the `Value` column (i.e discharge) then takes each individual observation of `Value` and calculates the percentile. ```{r} -pct_flow <- nunavut_stn_flows %>% - mutate(dayofyear = yday(Date), Year = year(Date)) %>% +pct_flow <- nunavut_stn_flows |> + mutate(dayofyear = yday(Date), Year = year(Date)) |> filter(dayofyear %in% yday(seq.Date(from = (Sys.Date()-30), - to = Sys.Date(), by = "day"))) %>% - group_by(dayofyear) %>% - mutate(prctile = ecdf(Value)(Value)) %>% - mutate(Date_no_year = dmy(paste0(day(Date),"-",month(Date),"-",year(Sys.Date())))) %>% + to = Sys.Date(), by = "day"))) |> + group_by(dayofyear) |> + mutate(prctile = ecdf(Value)(Value)) |> + mutate(Date_no_year = dmy(paste0(day(Date),"-",month(Date),"-",year(Sys.Date())))) |> ungroup() ``` To collect real time data, we can use the `realtime_dd()` function in `tidyhydat`. Because real time data is collected in hourly (or higher) intervals and we are operating on a daily basis, we first need to take a daily mean of discharge. Again this is accomplished in a pipe: ```{r realtime} -nunavut_realtime <- realtime_dd(unique(nunavut_stn_flows$STATION_NUMBER)) %>% - mutate(Date_day = as.Date(Date)) %>% - group_by(Date_day) %>% +nunavut_realtime <- realtime_dd(unique(nunavut_stn_flows$STATION_NUMBER)) |> + mutate(Date_day = as.Date(Date)) |> + group_by(Date_day) |> summarise(Value = mean(Value, na.rm = TRUE), .groups = "drop") ``` diff --git a/vignettes/tidyhydat_hydat_db.Rmd b/vignettes/tidyhydat_hydat_db.Rmd index 1f5623d..0b53d5f 100644 --- a/vignettes/tidyhydat_hydat_db.Rmd +++ b/vignettes/tidyhydat_hydat_db.Rmd @@ -83,8 +83,8 @@ Working with SQL tables in dplyr is much like working with regular data frames, ```r -tbl(src, "STN_OPERATION_SCHEDULE") %>% - filter(STATION_NUMBER == "05AA008") %>% +tbl(src, "STN_OPERATION_SCHEDULE") |> + filter(STATION_NUMBER == "05AA008") |> collect() #> # A tibble: 103 × 5 #> STATION_NUMBER DATA_TYPE YEAR MONTH_FROM MONTH_TO diff --git a/vignettes/tidyhydat_hydat_db.Rmd.orig b/vignettes/tidyhydat_hydat_db.Rmd.orig index ddf0f77..76e5484 100644 --- a/vignettes/tidyhydat_hydat_db.Rmd.orig +++ b/vignettes/tidyhydat_hydat_db.Rmd.orig @@ -59,8 +59,8 @@ tbl(src, "STN_OPERATION_SCHEDULE") Working with SQL tables in dplyr is much like working with regular data frames, except no data is actually read from the database until necessary. Because some of these tables are large (particularly those containing the actual data), you will want to `filter()` the tables before you `collect()` them (the `collect()` operation loads them into memory as a `data.frame`). ```{r} -tbl(src, "STN_OPERATION_SCHEDULE") %>% - filter(STATION_NUMBER == "05AA008") %>% +tbl(src, "STN_OPERATION_SCHEDULE") |> + filter(STATION_NUMBER == "05AA008") |> collect() ```