Skip to content

Instantly share code, notes, and snippets.

@andrewmoles2
Created April 13, 2023 13:29
Show Gist options
  • Save andrewmoles2/f2d321a1edbab36284d6f0ddcb1fb44e to your computer and use it in GitHub Desktop.
Save andrewmoles2/f2d321a1edbab36284d6f0ddcb1fb44e to your computer and use it in GitHub Desktop.
# code from http://r.iresmi.net/2023/04/05/cherry-blossom/ written into function for future use
get_blossom <- function(url = "http://atmenv.envi.osakafu-u.ac.jp/aono/kyophenotemp4/") {
GET(url) |>
content() |>
html_element("pre") |>
html_text2() |>
str_replace_all("\xc2\xa0", " ") |> # bad encoding needs correction
read_fwf(fwf_cols("ad" = c(7, 10),
"fifd" = c(17, 20),
"fufd" = c(22, 25),
"work" = c(27, 30),
"type" = c(32, 35),
"ref" = c(37, Inf)),
skip = 26,
na = c("", "NA", "-")) |>
remove_empty() |>
mutate(full_flowering_date = ymd(glue("{str_pad(ad, 4, 'left', '0')}{fufd}")),
full_flowering_date_doy = yday(full_flowering_date))
}
@andrewmoles2
Copy link
Author

All credit goes to this blog post - http://r.iresmi.net/2023/04/05/cherry-blossom/. I just wrote the extraction code into a function so I can use it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment