The DiseasyObservables
module is responsible for interfacing with the available diseasystores
and provide
disease data to the models.
The module primarily acts as a convenience wrapper around the diseasystores
. The observables and stratifications
will therefore depend on the data made available by the diseasystores.
See vignette("diseasy-observables")
Super class
diseasy::DiseasyBaseModule
-> DiseasyObservables
Active bindings
diseasystore
(
character
)
The set diseasystore to get DiseasyObservables for. Read-only.start_date
(
Date
)
The start date of the study period. Read-only.end_date
(
Date
)
The end date of the study period. Read-only.last_queryable_date
(
Date
)
The latest date that can be queried. Read-only.ds
(
Diseasystore*
)
The currently loaded diseasystore which provides the features. Read-only.available_observables
(
character
)
The currently available observables in the loaded diseasystore. Read-only.available_stratifications
(
character
)
The currently available stratifications in the loaded diseasystore. Read-only.slice_ts
(
Date
)
The timestamp to slice database on. Read-only.conn
(
DBIConnection
)
The connection to the database on. Read-only.
Methods
Method new()
Creates a new instance of the DiseasyObservables
R6 class.
Usage
DiseasyObservables$new(
diseasystore = NULL,
start_date = NULL,
end_date = NULL,
last_queryable_date = NULL,
conn = NULL,
slice_ts = NULL,
...
)
Arguments
diseasystore
(
character
)
A character string that controls which feature store to get data from.start_date
(
Date
)
Study period start (default values for get_observation).end_date
(
Date
)
Study period end (default values for get_observation).last_queryable_date
(
Date
)
Enforce a limit on data that can be pulled (not after this date).conn
(
DBIConnection
)
A database connection object (inherits from DBIConnection)slice_ts
(
Date
orcharacter
)
Date to slice the database on. SeeSCDB::get_table()
...
Parameters sent to
DiseasyBaseModule
R6 constructor.
Returns
A new instance of the DiseasyBaseModule
R6 class.
Method get_observation()
Retrieve an "observable" in the data set corresponding to the set diseasystore.
By default, the internal values for start_date and end_date are used to return data,
but these can be overwritten.
The results are cached for faster retrieval at subsequent calls.
Arguments
observable
(
character
)
The requested observable. Should follow the pattern 'n_*'.stratification
(
list
(quosures
))
DefaultNULL
. If given, expressions in stratification evaluated to give the stratification level.
Use rlang::quos(...) to specify stratification.start_date
(
Date
)
Start date to get DiseasyObservables for (including).end_date
(
Date
)
End date to get DiseasyObservables for (including).
Examples
# Create observables module using the Google COVID-19 data
obs <- DiseasyObservables$new(diseasystore = "Google COVID-19",
conn = DBI::dbConnect(RSQLite::SQLite()))
# See available observables
print(obs$available_observables)
#> [1] "n_population" "n_hospital" "n_deaths" "n_positive" "n_icu"
#> [6] "n_ventilator"
print(obs$available_stratifications)
#> [1] "age_group" "country_id" "country" "region_id"
#> [5] "region" "subregion_id" "subregion" "min_temperature"
#> [9] "max_temperature"
# Get data for one observable
if (FALSE) {
obs$get_observation("n_hospital",
start_date = as.Date("2020-03-01"),
end_date = as.Date("2020-03-05"))
}
rm(obs)