Skip to content

Commit

Permalink
Merge pull request #146 from cmu-delphi/ds/tab-complete
Browse files Browse the repository at this point in the history
fix: covidcast_epidata
  • Loading branch information
dshemetov authored Aug 12, 2023
2 parents 6593335 + 1261283 commit 1436691
Show file tree
Hide file tree
Showing 39 changed files with 166 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.7.1
current_version = 0.8.0
commit = False
tag = False

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ jobs:
DELPHI_EPIDATA_KEY: ${{ secrets.SECRET_EPIPROCESS_GHACTIONS_DELPHI_EPIDATA_KEY }}
with:
args: 'c("--no-manual", "--as-cran")'
build-args: 'c("--no-build-vignettes")'
error-on: '"error"'
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: epidatr
Type: Package
Title: Client for Delphi's Epidata API
Version: 0.7.1
Version: 0.8.0
Authors@R:
c(
person("Logan", "Brooks", email = "[email protected]", role = c("aut", "cre")),
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ S3method(as.data.frame,covidcast_data_signal_list)
S3method(as.data.frame,covidcast_data_source_list)
S3method(print,covidcast_data_signal)
S3method(print,covidcast_data_source)
S3method(print,covidcast_epidata)
S3method(print,epidata_call)
export("%>%")
export(covid_hosp_facility)
export(covid_hosp_facility_lookup)
export(covid_hosp_state_timeseries)
export(covidcast)
export(covidcast_epidata)
export(covidcast_meta)
export(delphi)
export(dengue_nowcast)
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# epidatr 0.8.0

- Fix source name duplication bug in `covidcast_epidata`
- Mark `covidcast_epidata` as experimental and do not export it

# epidatr 0.7.1

- Update README.md for better onboarding.
Expand All @@ -20,4 +25,4 @@ will output a nested list structure.
- The package that this installs is being renamed from `delphi.epidata` to
`epidatr`. To migrate, run the installation command above, followed by
`remove.packages("delphi.epidata")`, and adjust all references to the package
name accordingly.
name accordingly.
2 changes: 1 addition & 1 deletion R/constants.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version <- "0.7.1"
version <- "0.8.0"
http_headers <- httr::add_headers("User-Agent" = paste0("epidatr/", version), "Accept-Encoding" = "gzip")
global_base_url <- "https://api.delphi.cmu.edu/epidata/"
22 changes: 7 additions & 15 deletions R/covidcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,13 @@ print.covidcast_data_source <- function(source, ...) {
#' Creates a helper object that can use auto-complete to help find covidcast
#' sources and signals.
#'
#' @examples
#' covidcast_api <- covidcast_epidata()
#' print(covidcast_api) # print available sources and signals
#' fb_survey <- covidcast_api$sources$`fb-survey` # tab completion for sources
#' print(fb_survey) # print a verbose list of available signals
#' smoothed_cli <- fb_survey$signals$smoothed_cli # tab completion for signals
#' print(smoothed_cli)
#' df <- smoothed_cli$call("nation", "us", epirange(20210405, 20210410))
#' @param base_url optional alternative API base url
#' @param timeout_seconds the maximum amount of time to wait for a response
#' @importFrom httr stop_for_status content http_type
#' @importFrom jsonlite fromJSON
#' @importFrom xml2 read_html xml_find_all xml_text
#' @return an instance of covidcast_epidata
#'
#' @export
covidcast_epidata <- function(base_url = global_base_url, timeout_seconds = 30) {
url <- join_url(base_url, "covidcast/meta")
response <- do_request(url, list(), timeout_seconds)
Expand All @@ -130,11 +121,13 @@ covidcast_epidata <- function(base_url = global_base_url, timeout_seconds = 30)
sources <- do.call(c, lapply(response_content, parse_source, base_url = base_url))
class(sources) <- c("covidcast_data_source_list", class(sources))

all_signals <- do.call(c, lapply(sources, function(x) {
l <- c(x$signals)
names(l) <- paste(x$source, names(l), sep = ":")
l
}))
all_signals <- do.call(c, unname(
lapply(sources, function(x) {
l <- c(x$signals)
names(l) <- paste(x$source, names(l), sep = ":")
l
})
))
class(all_signals) <- c("covidcast_data_signal_list", class(all_signals))
structure(
list(
Expand All @@ -161,7 +154,6 @@ as.data.frame.covidcast_data_source_list <- function(sources, ...) {
}), ...)
}

#' @export
print.covidcast_epidata <- function(epidata, ...) {
print("COVIDcast Epidata Fetcher")
print("Sources:")
Expand Down
Loading

0 comments on commit 1436691

Please sign in to comment.