|
|
@ -1,3 +1,7 @@ |
|
|
|
utils::globalVariables( |
|
|
|
c("V1", "V2", "V3", "c_alpha", "conditions") |
|
|
|
) |
|
|
|
|
|
|
|
#' Start a session to F5 Weather |
|
|
|
#' |
|
|
|
#' @param user,pass F5 Weather creds; use `F5WX_USER` & `F5WX_PASS` environment |
|
|
@ -59,7 +63,9 @@ f5wx_login <- function(user = Sys.getenv("F5WX_USER"), |
|
|
|
#' Retrieve a forecast table from F5 Weather |
|
|
|
#' |
|
|
|
#' @param search for this location |
|
|
|
#' @return httr `response` object |
|
|
|
#' @return `f5wx_cast` object which is a `list` that contains a data frame of |
|
|
|
#' forecast information and an httr `response` object in the event |
|
|
|
#' you want to do more processing of the HTML table |
|
|
|
#' @export |
|
|
|
#' @examples \dontrun{ |
|
|
|
#' library(ggplot2) |
|
|
@ -101,23 +107,6 @@ f5wx_forecast <- function(search = "Dover, NH") { |
|
|
|
|
|
|
|
httr::stop_for_status(res) |
|
|
|
|
|
|
|
invisible(res) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#' Make a temperature & precipitation chart from the object returned by [f5wx_forecast()] |
|
|
|
#' |
|
|
|
#' @param res object returned by [f5wx_forecast()] |
|
|
|
#' @return ggplot2 object |
|
|
|
#' @export |
|
|
|
#' @examples \dontrun{ |
|
|
|
#' library(ggplot2) |
|
|
|
#' f5wx_login() |
|
|
|
#' res <- f5wx_forecast() |
|
|
|
#' f5wx_chart(res) + labs(title = "ECMWF Forecast for Berwick, Maine") |
|
|
|
#' } |
|
|
|
f5wx_chart <- function(res) { |
|
|
|
|
|
|
|
pg <- httr::content(res, as = "parsed") |
|
|
|
|
|
|
|
# model date location elevation in the <td> |
|
|
@ -179,6 +168,34 @@ f5wx_chart <- function(res) { |
|
|
|
c_alpha = replace_na(c_alpha, 1) |
|
|
|
) -> f_cast |
|
|
|
|
|
|
|
list( |
|
|
|
f_cast = f_cast, |
|
|
|
response = res |
|
|
|
) -> out |
|
|
|
|
|
|
|
class(out) <- c("f5wx_cast", "list") |
|
|
|
|
|
|
|
invisible(out) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#' Make a temperature & precipitation chart from the object returned by [f5wx_forecast()] |
|
|
|
#' |
|
|
|
#' @param res object returned by [f5wx_forecast()] |
|
|
|
#' @return ggplot2 object |
|
|
|
#' @export |
|
|
|
#' @examples \dontrun{ |
|
|
|
#' library(ggplot2) |
|
|
|
#' f5wx_login() |
|
|
|
#' res <- f5wx_forecast() |
|
|
|
#' f5wx_chart(res) + labs(title = "ECMWF Forecast for Berwick, Maine") |
|
|
|
#' } |
|
|
|
f5wx_chart <- function(res) { |
|
|
|
|
|
|
|
stopifnot(inherits(res, "f5wx_cast")) |
|
|
|
|
|
|
|
f_cast <- res$f_cast |
|
|
|
|
|
|
|
ggplot() + |
|
|
|
geom_segment( |
|
|
|
data = f_cast, |
|
|
@ -186,11 +203,11 @@ f5wx_chart <- function(res) { |
|
|
|
size = 5, lineend = "round" |
|
|
|
) + |
|
|
|
geom_text( |
|
|
|
data = f_cast, aes(V2, V1, label = sprintf("%s°", V2)), |
|
|
|
data = f_cast, aes(V2, V1, label = sprintf("%s\u00B0", V2)), |
|
|
|
hjust = 1, nudge_x = -0.75, size = 4, family = font_gs |
|
|
|
) + |
|
|
|
geom_text( |
|
|
|
data = f_cast, aes(V3, V1, label = sprintf("%s°", V3)), |
|
|
|
data = f_cast, aes(V3, V1, label = sprintf("%s\u00B0", V3)), |
|
|
|
hjust = 0, nudge_x = 0.75, size = 4, family = font_gs |
|
|
|
) + |
|
|
|
scale_x_continuous( |
|
|
|