@@ -21,25 +21,28 @@ extract_product_contents <- function(links, products) {
2121 # Otherwise, extract the node from within the HTML and return the text of
2222 # that node.
2323 contents <- contents | > purrr :: map_chr(.f = function (x ) {
24+
2425 txt <- safely_read_html(x )
2526 if (is.null(txt $ result )) {
2627 x
2728 } else if (is.null(txt $ error )) {
29+ xpath_to_use <- ifelse(is.na(rvest :: html_node(txt $ result , xpath = " //pre" )),
30+ " //table" , " //pre" )
31+ .progress <- FALSE
2832 txt $ result | >
29- rvest :: html_node (xpath = " //pre " ) | >
33+ rvest :: html_element (xpath = xpath_to_use ) | >
3034 rvest :: html_text() | >
3135 stringr :: str_replace_all(" \r " , " " ) | >
3236 stringr :: str_to_upper()
3337 }
3438 })
39+ contents
3540}
3641# ' concept for isolating this step
3742# ' @keywords internal
3843
3944parse_product_contents <- function (contents , products ){
40- f <- match.fun(products )
41- f(contents )
42- # purrr::map(.x= contents, .f = match.fun(products))
45+ purrr :: map(.x = contents , .f = match.fun(products ))
4346}
4447
4548# ' @title extract_storm_links
@@ -130,13 +133,13 @@ get_product <- function(links, products) {
130133# ' \dontrun{
131134# ' ## Get public advisories for first storm of 2016 Atlantic season.
132135# ' #get_storms(year = 2016, basin = "AL") |>
133- # ' # dplyr::slice( 1) |>
136+ # ' # dplyr::slice_head(n= 1) |>
134137# ' # pull(Link) |>
135138# ' # get_storm_data( products = "public")
136- # ' ## Get public advisories and storm discussions for first storm of 2017
139+ # ' ## Get public advisories and storm discussions for first storm of 2017
137140# ' Atlantic season.
138141# '# get_storms(year = 2017, basin = "AL") |>
139- # ' # slice( 1) |>
142+ # ' # slice_head(n= 1) |>
140143# ' # pull(Link) |>
141144# ' # get_storm_data(products = c("discus", "public"))
142145# ' }
@@ -147,8 +150,8 @@ get_storm_data <- function(links,
147150 " wndprb" )) {
148151
149152 products <- match.arg(products , several.ok = TRUE )
150- # extract_product_contents(links, products)
151- purrr :: map2(links , products , extract_product_contents )
153+
154+ purrr :: map2(links , products , extract_product_contents , .progress = FALSE )
152155}
153156
154157# ' @title get_product_links
0 commit comments