Skip to content

Instantly share code, notes, and snippets.

@wpetry
Created January 19, 2023 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpetry/7846b10621096443b87de3dafbc3729b to your computer and use it in GitHub Desktop.
Save wpetry/7846b10621096443b87de3dafbc3729b to your computer and use it in GitHub Desktop.
scrape billy barr's long-term snow data from https://www.gothicwx.org/
get_bb_snow <- function(){
require(rvest)
require(tidyverse)
require(janitor)
require(lubridate)
snow <- rvest::read_html("https://www.gothicwx.org/long-term-snow.html") %>%
rvest::html_element(".tableizer-table") %>%
rvest::html_table(header = TRUE, na.strings = c("NA", "")) %>%
janitor::row_to_names(1) %>%
janitor::clean_names() %>%
dplyr::select(-apr_01, -may_01) %>%
dplyr::rename_with(.fn = ~paste(stringr::str_extract(.x, "[a-z]{3}"), "cm",
sep = "_"),
.cols = sept:july) %>%
dplyr::rename(total_cm = total) %>%
tidyr::separate(winter_of, into = c("year_start", "year_end"), convert = TRUE) %>%
tidyr::drop_na(year_start, on_grnd) %>%
dplyr::mutate(year_end = year_start + 1L,
dplyr::across(sep_cm:total_cm, as.integer),
melt_date = lubridate::mdy(paste0("0", on_grnd, "/", year_end)),
melt_doy = lubridate::yday(melt_date)) %>%
dplyr::select(-on_grnd)
return(snow)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment