File tree 3 files changed +38
-4
lines changed
3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ Description: A wrapper around the 'COVID Tracking Project API'
11
11
in the US.
12
12
License: MIT + file LICENSE
13
13
Imports:
14
+ curl (>= 4.3),
14
15
dplyr (>= 0.8.3),
15
16
glue (>= 1.3.1),
16
17
httr (>= 1.4.1),
Original file line number Diff line number Diff line change @@ -63,7 +63,13 @@ get_states_daily <- function(state = "all", date = "all") {
63
63
# ' get_states_info()
64
64
# ' }
65
65
get_states_info <- function () {
66
- get(" states/info" ) %> %
66
+ tbl <- get(" states/info" )
67
+
68
+ if (nrow(tbl ) == 0 ) {
69
+ return (tbl )
70
+ }
71
+
72
+ tbl %> %
67
73
select(
68
74
state , name ,
69
75
everything()
@@ -95,7 +101,14 @@ get_us_current <- function() {
95
101
# ' get_us_daily()
96
102
# ' }
97
103
get_us_daily <- function () {
98
- get(" us/daily" ) %> %
104
+
105
+ tbl <- get(" us/daily" )
106
+
107
+ if (nrow(tbl ) == 0 ) {
108
+ return (tbl )
109
+ }
110
+
111
+ tbl %> %
99
112
rename(
100
113
n_states = states
101
114
) %> %
@@ -129,7 +142,13 @@ get_counties_info <- function() {
129
142
# ' get_tracker_urls()
130
143
# ' }
131
144
get_tracker_urls <- function () {
132
- get(" urls" ) %> %
145
+ tbl <- get(" urls" )
146
+
147
+ if (nrow(tbl ) == 0 ) {
148
+ return (tbl )
149
+ }
150
+
151
+ tbl %> %
133
152
rename(
134
153
state_name = name
135
154
) %> %
Original file line number Diff line number Diff line change @@ -63,9 +63,23 @@ request <- function(url) {
63
63
)
64
64
}
65
65
66
+ try_request <- purrr :: possibly(
67
+ request ,
68
+ otherwise = tibble(),
69
+ quiet = FALSE
70
+ )
71
+
66
72
get <- function (endpoint , query = " " ) {
67
73
url <- glue :: glue(" {base_url}{endpoint}{query}" )
68
- request(url )
74
+
75
+ have_internet <- curl :: has_internet()
76
+
77
+ if (! have_internet ) {
78
+ message(" No internet connection." )
79
+ return (tibble())
80
+ }
81
+
82
+ try_request(url )
69
83
}
70
84
71
85
replace_null <- function (x ) {
You can’t perform that action at this time.
0 commit comments