Skip to contents

Helper function for common Socrata open data API (SODA) queries targeted at data.cdc.gov datasets.

Usage

data_cdc_gov_soda_query(
  dataset_id,
  date_col = NULL,
  location_col = NULL,
  start_date = NULL,
  end_date = NULL,
  columns = NULL,
  locations = NULL,
  limit = 1e+05,
  order_by = NULL,
  desc = FALSE,
  ...
)

Arguments

dataset_id

Dataset ID for the dataset

date_col

Name of the date column for the dataset, if any. Default NULL.

location_col

Name of the location column for the dataset, if any. Default NULL.

start_date

Pull only rows with dates greater than or equal to this date. If NULL, no minimum date. Default NULL.

end_date

Pull only rows with dates less than or equal to this date. If NULL, no maximum date. Default NULL.

columns

Vector of columns to retrieve, in addition to the dataset's date and location columns, which are always retrieved. If NULL, retrieve all columns. Default NULL.

locations

Vector of locations to retrieve, in the format of the dataset's location column. If NULL, retrieve all. Default NULL.

limit

limit to the number of rows to retrieve. Default 1e5.

order_by

Vector of columns by which to order the results, if any. If NULL (default), order first by the date column, then by the location column. Having a default ordering makes queries more robust against unpredictable results.

desc

whether to order descending instead of ascending. Default FALSE (order ascending).

...

additional arguments (ignored for now)

Value

the query as soql::soql() output

Examples


data_cdc_gov_soda_query(
  "nhsn_hrd_prelim",
  "2025-05-01",
  "2025-07-01",
  "totalconfflunewadm")
#> https://data.cdc.gov/resource/nhsn_hrd_prelim.json?$where=2025-05-01%20%3E=%20'totalconfflunewadm'&$order=2025-05-01,2025-07-01&$limit=100000