MyNixOS website logo
Description

Retrieve 'AirNow' Air Quality Observations and Forecasts.

Retrieve air quality data via the 'AirNow' <https://www.airnow.gov/> API.

airnow

Lifecycle:experimental CRANstatus R-CMD-check Codecov testcoverage

airnow is an R package for querying and retrieving air quality information from AirNow via the AirNow API. Current and historical readings as well as forecasts can be retrieved as tidy data frames.

Installation

You can install the stable version of airnow from CRAN:

install.packages("airnow")

If you’d like to try out the development version of airnow, you can install directly from GitHub:

# install.packages("remotes")
remotes::install_github("briandconnelly/airnow")

Creating an API Token

The AirNow API is generally free to use. The set_airnow_token() function can be used to help you create and configure your API token.

library(airnow)

set_airnow_token()

Examples

Current air quality in Seattle

The AirNow API allows you to query air conditions either by ZIP code or latitude/longitude. Here, we’ll get the current conditions in Seattle by ZIP code:

library(airnow)

get_airnow_conditions(zip = "98101")
#> # A tibble: 2 × 11
#>   date_observed hour_obs…¹ local…² repor…³ state…⁴ latit…⁵ longi…⁶ param…⁷   aqi
#>   <date>             <int> <fct>   <fct>   <fct>     <dbl>   <dbl> <fct>   <int>
#> 1 2022-10-29            17 PST     Seattl… WA         47.6   -122. O3         25
#> 2 2022-10-29            17 PST     Seattl… WA         47.6   -122. PM2.5      38
#> # … with 2 more variables: category_number <int>, category_name <fct>, and
#> #   abbreviated variable names ¹​hour_observed, ²​local_time_zone,
#> #   ³​reporting_area, ⁴​state_code, ⁵​latitude, ⁶​longitude, ⁷​parameter

Find the site with the lowest air quality near Washington state

library(airnow)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

get_airnow_area(
  box = c(-125.394211, 45.295897, -116.736984, 49.172497),
  verbose = TRUE
) |>
  slice_max(order_by = aqi, n = 1) |>
  select(site_name, site_agency, latitude, longitude, aqi, datetime_observed)
#> # A tibble: 1 × 6
#>   site_name            site_agency     latit…¹ longi…²   aqi datetime_observed  
#>   <fct>                <fct>             <dbl>   <dbl> <int> <dttm>             
#> 1 Chehalis-Market Blvd Washington Dep…    46.7   -123.   129 2022-10-30 00:00:00
#> # … with abbreviated variable names ¹​latitude, ²​longitude

Disclaimer

This package and its author are not affiliated with AirNow or its partners. See the Data Exchange Guidelines for more details about this data set and how it should be used. Data are typically refreshed once per hour. Please be kind to this service and limit your request rate.

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows