Learn R Programming

tidycovid19 (version 0.0.0.9000)

download_apple_mtr_data: Download Apple Mobility Trend Reports Data

Description

Downloads Mobility Trends Reports provided by Apple related to Covid-19 (https://www.apple.com/covid19/mobility).

Usage

download_apple_mtr_data(
  type = "country",
  url = NULL,
  silent = FALSE,
  cached = FALSE
)

Arguments

type

The type of data that you want to retrieve. Can be any subset of

  • "country": Mobility trends by country.

  • "country_region": Mobility trends by country regions as classified by Apple (only available for some countries).

  • "country_city": Mobility trends by city as classified by Apple (only available for some countries).

url

The URL of the Apple Mobility Trend Reports is burried in Java Script, making it non-trivial to parse. The Github repository of this package contains an R script that uses the 'RSelenium' package and headless browsing to scrape the URL. The scraped URL is included in the daily updated data contained in this repository. By default, the function uses this cached URL to retrieve the data. You can, however, pass your own URL by setting this variable. Defaults to NULL to trigger loading the cached URL.

silent

Whether you want the function to send some status messages to the console. Might be informative as downloading will take some time and thus defaults to TRUE.

cached

Whether you want to download the cached version of the data from the tidycovid19 Github repository instead of retrieving the data from the authorative source. Downloading the cached version is faster and the cache is updated daily. Defaults to FALSE.

Value

A data frame containing the data. It includes a timestamp variable indicating the time of data retrieval.

Examples

Run this code
# NOT RUN {
df <- download_apple_mtr_data(silent = TRUE, cached = TRUE)
df %>%
  dplyr::group_by(date) %>%
  dplyr::summarize(
    walking = mean(walking, na.rm = TRUE)
  ) %>%
  ggplot2::ggplot(ggplot2::aes(x = date, y = walking)) +
  ggplot2::geom_line()

df <- download_apple_mtr_data(type = "country_city", silent = TRUE, cached = TRUE)
df %>%
  dplyr::filter(iso3c == "DEU") %>%
  ggplot2::ggplot(ggplot2::aes(x = date, y = driving, color = city)) +
  ggplot2::geom_line()

# }

Run the code above in your browser using DataLab