airpurifyr
makes it easy to grab air quality data from
OpenAQ.
You can install the development version of airpurifyr
from
GitHub with:
# install.packages("devtools")
devtools::install_github("numbats/airpurifyr")
You will need to register an API key, which you can do
here. Keep note of the API key,
and set it using set_openaq_api_key()
.
If you are using the package regularly, you can set this API key using a
.Renviron
or inside your .Rprofile
, but don’t share it publicly!
To get data, use the function get_measurements_for_location()
. You’ll
probably want to provide at least a country, and maybe a city. For
example,
melbourne_data <- get_measurements_for_location(country = "AU", city = "Melbourne")
You may also want to filter by locations, which are almost like suburbs but are dependent on the location of sensors. More info on the API fields can be found on the OpenAQ Documentation.