Skip to content

Commit a6bd152

Browse files
authored
Merge pull request #211 from ropensci/ew1
Clean up outdated and deprecated code
2 parents c9c327d + 8289ba9 commit a6bd152

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

‎DESCRIPTION‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,32 @@ Suggests:
4949
rmarkdown,
5050
rnaturalearthdata (>= 0.1),
5151
sf (>= 1.0),
52-
sp,
52+
terra,
5353
testthat
5454
Config/Needs/website: rrricanesdata, gganimate, magick
5555
VignetteBuilder: knitr
5656
Encoding: UTF-8
57-
RoxygenNote: 7.1.2
57+
RoxygenNote: 7.3.2
58+
Collate:
59+
'base.R'
60+
'data.R'
61+
'discus.R'
62+
'filters.R'
63+
'fstadv.R'
64+
'get_storm_data.R'
65+
'get_storm_list.R'
66+
'get_storms.R'
67+
'get_track.R'
68+
'get_url_contents.R'
69+
'gis.R'
70+
'Movement_fstadv.R'
71+
'posest.R'
72+
'prblty.R'
73+
'products.R'
74+
'public.R'
75+
'scrapers.R'
76+
'tidy_fstadv.R'
77+
'tracking_chart.R'
78+
'update.R'
79+
'utils.R'
80+
'wndprb.R'

‎R/base.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
#' \code{rrricanes.working_msg} is set to FALSE by default. When TRUE, it will
112112
#' list the current storm, advisory and date being worked.
113113
#'
114-
#' @docType package
114+
#' @docType _PACKAGE
115115
#' @name rrricanes
116116
NULL
117117

‎R/get_storm_data.R‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3944
parse_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

‎R/get_url_contents.R‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ get_url_contents <- function(links) {
3737
groups <- ceiling(seq_along(1:length(links))/80)
3838
grouped_links <- split(links, groups)
3939

40-
# Set progress bar
41-
p <- dplyr::progress_estimated(n = length(links))
42-
4340
contents <-
4441
grouped_links |>
4542
purrr::imap(.f = function(x, y) {
@@ -48,18 +45,16 @@ get_url_contents <- function(links) {
4845
# Send group of links to `download_txt`
4946
txt <- download_text(x)
5047
# We are not in the last group; apply a delay
51-
p$tick()$print()
5248
if (getOption("rrricanes.working_msg"))
5349
message("Waiting 10 seconds to retrieve large numbers of links.")
54-
p$pause(10)
5550
txt
5651
} else {
5752
# Send group of links to `download_txt`
58-
p$tick()$print()
5953
download_text(x)
6054
}
6155
})
62-
contents <- unsplit(contents, groups)
63-
contents
64-
#purrr::flatten_chr(contents)
56+
57+
contents <- unsplit(contents, groups)
58+
#purrr::list_c(contents)
59+
contents
6560
}

‎R/prblty.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ prblty <- function(contents) {
7575
.,
7676
"X",
7777
"O")))
78-
print(prblty())
78+
7979
# Convert date
8080
prblty <- prblty |> dplyr::mutate(
8181
Date =

0 commit comments

Comments
 (0)