Skip to content

Commit

Permalink
Merge pull request #155 from cmu-delphi/djm/endpointfun
Browse files Browse the repository at this point in the history
Djm/endpointfun
  • Loading branch information
dshemetov authored Aug 30, 2023
2 parents 7f2d73a + f3db34a commit 5b97c88
Show file tree
Hide file tree
Showing 40 changed files with 397 additions and 231 deletions.
3 changes: 1 addition & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
^.*\.Rproj$
^.*\..Rcheck$
^\.Rproj\.user$

^DEVELOPMENT\.md$
^doc$
^shiny$
^docs$
^Meta$
^_pkgdown\.yml$
^pkgdown$
^data-raw$
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ on:
jobs:
build:
runs-on: ubuntu-20.04
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
r-version: 4.0

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::devtools, any::rcmdcheck, local::.
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
env:
DELPHI_EPIDATA_KEY: ${{ secrets.SECRET_EPIPROCESS_GHACTIONS_DELPHI_EPIDATA_KEY }}
with:
args: 'c("--no-manual", "--as-cran")'
error-on: '"error"'
16 changes: 0 additions & 16 deletions vignettes/development.rmd → DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
---
title: "Notes for Developers"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Notes for Developers}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

## Development Environment

Relevant R commands
Expand Down
Binary file removed Meta/vignette.rds
Binary file not shown.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ S3method(print,covidcast_data_signal)
S3method(print,covidcast_data_source)
S3method(print,epidata_call)
export("%>%")
export(avail_endpoints)
export(covid_hosp_facility)
export(covid_hosp_facility_lookup)
export(covid_hosp_state_timeseries)
Expand Down
20 changes: 20 additions & 0 deletions R/avail_endpoints.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' List all available endpoints
#'
#' @return A [`tibble::tibble`] with 2 columns. `Endpoint` contains the function
#' for accessing the Delphi Epidata API endpoint along with a `Description`.
#' @export
#'
#' @examples
#' endps <- avail_endpoints()
#' print(endps, n = nrow(endps))
avail_endpoints <- function() {
h <- help.search("endpoint",
package = "epidatr", fields = "concept",
agrep = FALSE
)$matches
tib <- tibble::tibble( # printing is much nicer than data.frame
Endpoint = paste0(h$Name, "()"),
Description = h$Title
)
tib
}
89 changes: 51 additions & 38 deletions R/covidcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,34 @@ parse_source <- function(source, base_url) {

#' @method as.data.frame covidcast_data_signal_list
#' @export
as.data.frame.covidcast_data_signal_list <- function(signals, ...) {
as.data.frame(do.call(rbind, lapply(signals, function(x) {
sub <- x[c(
"source",
"signal",
"name",
"active",
"short_description",
"description",
"time_type",
"time_label",
"value_label",
"format",
"category",
"high_values_are",
"is_smoothed",
"is_weighted",
"is_cumulative",
"has_stderr",
"has_sample_size"
)]
sub$geo_types <- paste0(names(x$geo_types), collapse = ",")
sub
})), row.names = sapply(signals, function(x) {
x$key
}), ...)
as.data.frame.covidcast_data_signal_list <- function(x, ...) {
as.data.frame(
do.call(rbind, lapply(x, function(z) {
sub <- z[c(
"source",
"signal",
"name",
"active",
"short_description",
"description",
"time_type",
"time_label",
"value_label",
"format",
"category",
"high_values_are",
"is_smoothed",
"is_weighted",
"is_cumulative",
"has_stderr",
"has_sample_size"
)]
sub$geo_types <- paste0(names(z$geo_types), collapse = ",")
sub
})),
row.names = sapply(x, function(y) y$key),
...
)
}

#' @export
Expand Down Expand Up @@ -152,18 +154,29 @@ covidcast_epidata <- function(base_url = global_base_url, timeout_seconds = 30)

#' @method as.data.frame covidcast_data_source_list
#' @export
as.data.frame.covidcast_data_source_list <- function(sources, ...) {
as.data.frame(do.call(rbind, lapply(sources, function(x) {
sub <- x[c(
"source", "name", "description", "reference_signal", "license"
)]
sub$signals <- paste0(sapply(x$signals, function(y) {
y$signal
}), collapse = ",")
sub
})), row.names = sapply(sources, function(x) {
x$source
}), ...)
as.data.frame.covidcast_data_source_list <- function(x, ...) {
as.data.frame(
do.call(
rbind,
lapply(
x,
FUN = function(z) {
cols <- c(
"source", "name", "description", "reference_signal",
"license"
)
sub <- z[cols]
sub$signals <- paste0(
sapply(z$signals, function(y) y$signal),
collapse = ","
)
sub
}
)
),
row.names = sapply(x, function(z) z$source),
...
)
}

print.covidcast_epidata <- function(x, ...) {
Expand Down
Loading

0 comments on commit 5b97c88

Please sign in to comment.