Skip to contents

The Respiratory viruses weekly repository contains weekly summaries of the erviss data for Influenza-Like Illness (ILI) and Acute Respiratory Infection (ARI).

This vignette shows how to use (some of) this data through the diseasystore package.

First, it is a good idea to clone the repository locally and store that location as an option for the package.

# First we set the path we want to use as an option
options(
  "diseasystore.DiseasystoreEcdcRespiratoryViruses.source_conn" =
    file.path("local", "path")
)

# Ensure folder exists
source_conn <- diseasyoption("source_conn", "DiseasystoreEcdcRespiratoryViruses")
if (!dir.exists(source_conn)) {
  dir.create(source_conn, recursive = TRUE, showWarnings = FALSE)
}

# Clone the repository
system2(
  "git",
  args = c(
    paste("-C", source_conn),
    "clone https://github.com/EU-ECDC/Respiratory_viruses_weekly_data"
  ),
  stdout = TRUE
)

The diseasystores require a database to store its features in. These should be configured before use and can be stored in the packages options.

# We define target_conn as a function that opens a DBIconnection to the DB
target_conn <- \() DBI::dbConnect(duckdb::duckdb())
options(
  "diseasystore.DiseasystoreEcdcRespiratoryViruses.target_conn" = target_conn
)

Once the files are downloaded and the target database is configured, we can initialize the diseasystore that uses the ECDC Respiratory Viruses Weekly data.

Once configured such, we can use the feature store directly to get data.

# We can see all the available features in the feature store
ds$available_features
#> [1] "iliari_rates"   "infection_type" "age_group"

If you have locally cloned the repository, you may consider pulling data from the repository manually and disabling automatic pulls. Otherwise, the diseasystore will check for updates every time you request a feature.

# Manually update the repository
system2(
  "git",
  args = paste("-C", diseasyoption("source_conn", "DiseasystoreEcdcRespiratoryViruses")),
  stdout = TRUE
)

# Disable automatic pulls
options("diseasystore.DiseasystoreEcdcRespiratoryViruses.pull" = FALSE)
# And then retrieve a feature from the feature store
ds$get_feature(feature = "iliari_rates",
               start_date = as.Date("2023-01-01"),
               end_date = as.Date("2023-03-01"))
#> Note: method with signature 'DBIConnection#Id' chosen for function 'dbExistsTable',
#>  target signature 'duckdb_connection#Id'.
#>  "duckdb_connection#ANY" would also be valid
#> # Source:   table<dbplyr_ZQdHOrDslY> [?? x 6]
#> # Database: DuckDB v1.1.3 [unknown@Linux 6.5.0-1025-azure:R 4.4.2/:memory:]
#>   key_location age_group infection_type  rate valid_from valid_until
#>   <chr>        <chr>     <chr>          <dbl> <date>     <date>     
#> 1 Austria      65+       ILI             404. 2023-02-27 2023-03-06 
#> 2 Austria      15-64     ILI            3144. 2023-02-20 2023-02-27 
#> 3 Austria      15-64     ILI            2177. 2023-02-06 2023-02-13 
#> 4 Austria      15-64     ILI            2295. 2023-01-30 2023-02-06 
#> 5 Austria      05-14     ILI            1723. 2023-01-30 2023-02-06 
#> # ℹ more rows