Skip to content

Instantly share code, notes, and snippets.

@boshek
Created May 18, 2021 15:50
Show Gist options
  • Save boshek/83734889f01834f455c7b7fa391bcad7 to your computer and use it in GitHub Desktop.
Save boshek/83734889f01834f455c7b7fa391bcad7 to your computer and use it in GitHub Desktop.
library(tidyhydat)
library(dplyr)
library(purrr)
rl_stations <- realtime_stations(prov_terr_state_loc = "BC")
hy_stations <- hy_stations(prov_terr_state_loc = "BC")
## all stations that are both in hydat and have a realtime record
bc_stations <- rl_stations %>%
inner_join(hy_stations, by = "STATION_NUMBER")
find_station_gap <- function(station_number) {
data.frame(
station_number = station_number,
station_name = hy_stations(station_number)$STATION_NAME,
earliest_rl_date = as.Date(min(realtime_dd(station_number)$Date)),
latest_hydat_date = max(hy_daily(station_number)$Date)
)
}
station_gaps <- map_df(bc_stations$STATION_NUMBER, find_station_gap)
write.csv(station_gaps,
file = paste0("station-gap-", as.Date(hy_version()$Date), ".csv"),
row.names = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment