Created
January 19, 2023 13:19
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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