Learn R Programming

infectiousR (version 0.1.1)

get_covid_stats_by_country_name: Get COVID-19 Statistics for a Specific Country

Description

Retrieves COVID-19 totals for a given country using the 'disease.sh' API.

Usage

get_covid_stats_by_country_name(
  country,
  yesterday = FALSE,
  twoDaysAgo = FALSE,
  strict = TRUE,
  allowNull = FALSE
)

Value

A data frame with the following columns:

  • country: Country name.

  • updated: Timestamp of last update (POSIXct in UTC).

  • cases: Total confirmed cases.

  • todayCases: New confirmed cases today.

  • deaths: Total deaths.

  • recovered: Total recoveries.

  • population: Estimated population.

Returns NULL if the API is unavailable, the country is not found, or an error occurs.

Arguments

country

Character. A country name, ISO2, ISO3 code, or country ID.

yesterday

Logical. If TRUE, gets data reported from the previous day. Default is FALSE.

twoDaysAgo

Logical. If TRUE, gets data reported two days ago. Default is FALSE.

strict

Logical. If TRUE (default), disables fuzzy matching (e.g., avoids confusion between "Oman" and "Romania").

allowNull

Logical. If TRUE, allows null values (returned as NA). Default is FALSE.

Details

This function accesses COVID-19 data for a specific country based on its name or ISO code. Requires an active internet connection.

References

API Docs: https://disease.sh/docs/#/COVID-19

Examples

Run this code
if (FALSE) {
# Get data for Brazil
brazil_data <- get_covid_stats_by_country_name("Brazil")
if (!is.null(brazil_data)) {
  print(brazil_data)
}

# Get data for the USA using ISO2 code
usa_data <- get_covid_stats_by_country_name("US", yesterday = TRUE)
}

Run the code above in your browser using DataLab