From 6c21cf8338c40690ddfd32f277dd39f42bcfb376 Mon Sep 17 00:00:00 2001 From: "Dr. Chester Ismay" Date: Fri, 10 Jan 2025 12:16:23 -0700 Subject: [PATCH] adjust timezone and address missing values in weather information (#25) --------- Co-authored-by: Simon P. Couch --- DESCRIPTION | 3 ++- NEWS.md | 5 ++++- R/utils.R | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4a4fa2e..e7792ec 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,8 @@ Imports: curl, usethis, roxygen2, - progress + progress, + tidyr URL: https://github.com/simonpcouch/anyflights, https://simonpcouch.github.io/anyflights/ BugReports: https://github.com/simonpcouch/anyflights/issues RoxygenNote: 7.2.3 diff --git a/NEWS.md b/NEWS.md index 5863746..ccbac55 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ ## v 0.3.4.9000 - +* Include `tz = "GMT"` argument to `ISOdatetime()` so that weather output isn't + affected by the user's local timezone (#25, @ismayc). +* Fill in missing values of `temp`, `dewp`, `humid`, `precip`, and `pressure` + since they are only recorded once an hour in the source data (#25, @ismayc). ## v 0.3.4 diff --git a/R/utils.R b/R/utils.R index 029541b..b4f7eac 100644 --- a/R/utils.R +++ b/R/utils.R @@ -438,9 +438,18 @@ get_weather_for_station <- function(station, year, dir, month = as.integer(lubridate::month(time)), day = lubridate::mday(time), hour = lubridate::hour(time), - time_hour = ISOdatetime(year, month, day, hour, 0, 0)) %>% + # ensure output isn't shifted for current timezone of user + time_hour = ISOdatetime(year, month, day, hour, 0, 0, + tz = "GMT")) %>% # filter to only relevant rows - necessary for discontinuous month ranges dplyr::filter(month %in% !!month) %>% + # fill in missing values with the only value given in a particular hour + dplyr::group_by(time_hour) %>% + # fill NAs + tidyr::fill(temp, dewp, humid, precip, pressure, + .direction = "downup") %>% + # ungroup to return to original data structure + dplyr::ungroup() %>% # remove duplicates / incompletes dplyr::group_by(origin, month, day, hour) %>% dplyr::filter(dplyr::row_number() == 1) %>%