Skip to contents

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. R-CMD-check Codecov test coverage

An R package for interacting with the OpenAQ API.

Installation

The package is available to install through Github. Use the install_github command from remotes package.

library("remotes")

install_github("openaq/openaq-r@*release")

Quickstart

For a full walkthrough on using openaq we recommend that you read through the “Introduction to openaq” vignette (vignette("openaq")). The following guide is a quick and minimal example to get you started.

  1. Register for an account at https://explore.openaq.org/register.
  2. Find your API key in the user account page.
  3. Save your API key as the OPENAQ_API_KEY environment variable . e.g. OPENAQ_API_KEY=yourkey in .Renviron. See help(openaq) for other ways to use and access your API key.

Now we can query OpenAQ for air quality monitoring locations. For this example we will query locations that measure PM2.5 near (with 10km) Antananarivo, Madagascar (-18.90848, 47.53751)

library(openaq)

locations <- list_locations(
    parameters_id = 2, 
    coordinates = list(-18.90848, 47.53751),
    radius = 10000
)

This returns a data frame that will look something like:

id name is_mobile is_monitor timezone countries_id country_name country_iso latitude longitude datetime_first datetime_last owner_name providers_id provider_name
41726 Antananarivo FALSE TRUE Indian/Antananarivo 182 Madagascar MG -18.90848 47.53751 2020-12-22 07:00:00 2025-01-17 20:00:00 Unknown Governmental Organization 119 AirNow

Development

Contributions are welcome. See the contribution guide for general information about contributing to the package.

Specific guidelines for contributions the openaq package:

  • Code contributions must follow lint convention using lintr, see the .lintr file for specifics.

  • Code contributions must include unit test, iether updated or wholly new, depending on the contribution. See testing README for more information.

  • Limit new dependencies. While adding new external dependencies is not out of the question, we seek to keep external dependencies at a minimum. When possible use base R functionality. Code contributions that rely on external dependencies should be discussed with the package maintainer first.