Skip to content

Commit 677f4cd

Browse files
committed
Address review comments
1 parent b10569f commit 677f4cd

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

R-packages/covidcast/R/covidcast.R

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,17 @@ covidcast_days <- function(data_source, signal, start_day, end_day, geo_type,
532532
for (i in seq(ndays + 1)) {
533533
query_day <- start_day + i - 1
534534
day_str <- date_to_string(query_day)
535-
res <- covidcast(data_source = data_source,
536-
signal = signal,
537-
time_type = "day",
538-
geo_type = geo_type,
539-
time_values = day_str,
540-
geo_value = geo_value,
541-
as_of = as_of,
542-
issues = issues,
543-
lag = lag)
544-
545-
if (is.null(res)) {
535+
response <- covidcast(data_source = data_source,
536+
signal = signal,
537+
time_type = "day",
538+
geo_type = geo_type,
539+
time_values = day_str,
540+
geo_value = geo_value,
541+
as_of = as_of,
542+
issues = issues,
543+
lag = lag)
544+
545+
if (is.null(response)) {
546546
warn(paste0("Fetching ", signal, " from ", data_source, " for ",
547547
query_day, " in geography '", geo_value, "': no results"),
548548
data_source = data_source,
@@ -554,7 +554,7 @@ covidcast_days <- function(data_source, signal, start_day, end_day, geo_type,
554554
next
555555
}
556556

557-
dat[[i]] <- res
557+
dat[[i]] <- response
558558

559559
summary <- sprintf(
560560
"Fetched day %s: num_entries = %s",
@@ -650,16 +650,18 @@ covidcast <- function(data_source, signal, time_type, geo_type, time_values,
650650
params$lag <- lag
651651
}
652652

653-
# Make the API call
654-
res <- .request(params)
655-
if (nchar(res) == 0) {
653+
# Make the API call. If the API returns a non-200 status code, indicating e.g.
654+
# a database error, .request() raises an error. It returns an empty string if
655+
# there are no results for our query.
656+
response <- .request(params)
657+
if (nchar(response) == 0) {
656658
# empty if no results
657659
return(NULL)
658660
}
659661

660662
# geo_value must be read as character so FIPS codes are returned as character,
661663
# not numbers (with leading 0s potentially removed)
662-
return(read.csv(textConnection(res), stringsAsFactors = FALSE,
664+
return(read.csv(textConnection(response), stringsAsFactors = FALSE,
663665
colClasses = c("geo_value" = "character")))
664666
}
665667

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
geo_value,signal,time_value,direction,issue,lag,value,stderr,sample_size
22
01001,bar,20200110,,20200111,1,91.2,0.8,114.2
3-
01002,bar,20200110,,20200111,1,99.1,0.2,217.8
3+
01002,bar,20200110,,20200111,1,99.1,0.2,217.8
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
geo_value,signal,time_value,direction,issue,lag,value,stderr,sample_size
22
31001,bar,20200112,,20200113,1,81.2,0.8,314.2
3-
31002,bar,20200112,,20200113,1,89.1,0.2,417.8
3+
31002,bar,20200112,,20200113,1,89.1,0.2,417.8

R-packages/covidcast/tests/testthat/test-covidcast.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ with_mock_api({
149149
})
150150

151151
test_that("covidcast_signal stops when end_day < start_day", {
152-
# reusing api.php-d2e163.json for metadata
152+
# reusing api.php-dd024f.csv for metadata
153153
expect_error(covidcast_signal("foo", "bar", "2020-01-02", "2020-01-01"))
154154
})
155155

0 commit comments

Comments
 (0)