@@ -438,9 +438,9 @@ covidcast_meta <- function() {
438438 }
439439
440440 meta <- meta $ epidata %> %
441- dplyr :: mutate(min_time = as.Date(as.character( . data$ min_time ), format = " %Y%m%d " ),
442- max_time = as.Date(as.character( . data$ max_time ), format = " %Y%m%d " ),
443- max_issue = as.Date(as.character( . data$ max_issue ), format = " %Y%m%d " ))
441+ dplyr :: mutate(min_time = api_to_date( . data$ min_time ),
442+ max_time = api_to_date( . data$ max_time ),
443+ max_issue = api_to_date( . data$ max_issue ))
444444
445445 class(meta ) <- c(" covidcast_meta" , " data.frame" )
446446 return (meta )
@@ -589,15 +589,18 @@ covidcast_days <- function(data_source, signal, start_day, end_day, geo_type,
589589 }
590590 if (dat [[i ]]$ message == " success" ) {
591591 desired_geos <- tolower(unique(geo_value ))
592+
592593 returned_epidata <- dat [[i ]]$ epidata
593594 returned_geo_array <- returned_epidata %> %
594- select(geo_value , time_value ) %> %
595- group_by(time_value ) %> %
596- summarize(geo_value = list (geo_value ))
595+ dplyr :: select(geo_value , time_value ) %> %
596+ dplyr :: group_by(time_value ) %> %
597+ dplyr :: summarize(geo_value = list (geo_value ))
597598 returned_time_values <- returned_geo_array $ time_value
599+
598600 if (length(returned_time_values ) != length(time_values )) {
599601 missing_time_values <- setdiff(time_values , returned_time_values )
600- missing_dates <- ymd(missing_time_values )
602+ missing_dates <- api_to_date(missing_time_values )
603+
601604 warn(sprintf(" Data not fetched for the following days: %s" ,
602605 paste(missing_dates , collapse = " , " )),
603606 data_source = data_source ,
@@ -611,6 +614,7 @@ covidcast_days <- function(data_source, signal, start_day, end_day, geo_type,
611614 if (! identical(" *" , geo_value )) {
612615 missing_geo_array <- returned_geo_array [
613616 lapply(returned_geo_array $ geo_value , length ) < length(desired_geos ), ]
617+
614618 if (nrow(missing_geo_array ) > 0 ) {
615619 missing_geo_array $ warning <-
616620 unlist(apply(returned_geo_array ,
@@ -620,7 +624,7 @@ covidcast_days <- function(data_source, signal, start_day, end_day, geo_type,
620624 warn(missing_geo_array $ warning ,
621625 data_source = data_source ,
622626 signal = signal ,
623- day = ymd (missing_geo_array $ time_value ),
627+ day = api_to_date (missing_geo_array $ time_value ),
624628 geo_value = geo_value ,
625629 api_msg = dat [[i ]]$ message ,
626630 class = " covidcast_missing_geo_values" )
@@ -647,8 +651,8 @@ covidcast_days <- function(data_source, signal, start_day, end_day, geo_type,
647651
648652 if (nrow(df ) > 0 ) {
649653 # If no data is found, there is no time_value column to report
650- df $ time_value <- as.Date(as.character( df $ time_value ), format = " %Y%m%d " )
651- df $ issue <- as.Date(as.character( df $ issue ), format = " %Y%m%d " )
654+ df $ time_value <- api_to_date( df $ time_value )
655+ df $ issue <- api_to_date( df $ issue )
652656 df $ data_source <- data_source
653657 df $ signal <- signal
654658
@@ -668,7 +672,7 @@ geo_warning_message <- function(row, desired_geos) {
668672 if (length(missing_geos ) > 0 ) {
669673 missing_geos_str <- paste0(missing_geos , collapse = " , " )
670674 err_msg <- sprintf(" Data not fetched for some geographies on %s: %s" ,
671- ymd (row $ time_value ), missing_geos_str )
675+ api_to_date (row $ time_value ), missing_geos_str )
672676 return (err_msg )
673677 }
674678}
@@ -755,3 +759,8 @@ covidcast <- function(data_source, signal, time_type, geo_type, time_values,
755759date_to_string <- function (mydate ) {
756760 format(mydate , " %Y%m%d" )
757761}
762+
763+ # Convert dates from API to Date objects
764+ api_to_date <- function (str ) {
765+ as.Date(as.character(str ), format = " %Y%m%d" )
766+ }
0 commit comments