aiRly is an unofficial R wrapper for Airly, platform which mission is to monitor and inform millions of people about the current state of air quality.

Installation

aiRly is available on CRAN, so you can install it using

Also, you can install current development version of aiRly from GitHub with:

devtools::install_github("piotrekjanus/aiRly")

Set developer account

First, you should start with setting your Airly developer account at Airly developer. After you receive key, it’s time to make a use of this package!

Example

This is a basic example of package usage.

Let’s find out if there are any near stations somewhere in Krakow, Poland. We will look for stations in a range of 20 km. We set max_results to -1 in order to get all stations in the neighborhood.

library(aiRly)

api_key <- Sys.getenv("api_key")
set_apikey(api_key)

stations <- get_nearest_installations(50.11670, 19.91429, max_distance = 20, max_results = -1)

Let’s filter only for Airly stations and choose those which are located at the highest and lowest point a.s.l.

Ok, we have just received information about current state, last 24h history and forecasts for next day for both installations.

Let’s make some visualizations

We can see that most of the time, air quality is worse (and will be) in lower part of Krakow. Ok, but are those sensors readings indicating high pollution? We can check it using get_indexes function, which fill translate values of AIRLY_CAQI variable

After we made few requests, we would like to check how many we have left. For that purpose, simply use remaining_requests

rem_req <- remaining_requests()
cat("Available requests \n", rem_req$remaining, "/", rem_req$limit)
#> Available requests 
#>  94 / 100