Provides the latest value of each available parameter for every location in the system.
aq_latest(country = NULL, city = NULL, location = NULL,
parameter = NULL, has_geo = NULL, limit = 10000, latitude = NULL,
longitude = NULL, radius = NULL, page = NULL)Limit results by a certain country -- a two-letters code see countries() for finding code based on name.
Limit results by a certain city.
Limit results by a certain location.
Limit to only a certain parameter (valid values are 'pm25', 'pm10', 'so2', 'no2', 'o3', 'co' and 'bc'). If no parameter is given, all parameters are retrieved.
has_geo Filter out items that have or do not have geographic information.
Change the number of results returned, max is 10000.
Latitude of the center point (lat, lon) used to get measurements within a certain area.
Longitude of the center point (lat, lon) used to get measurements within a certain area.
Radius (in meters) used to get measurements within a certain area, must be used with latitude and longitude
The page of the results to query. This can be useful if e.g. there are 2000 measurements, then first use page=1 and page=2 with limit=100 to get all measurements for your query.
A results data.frame (dplyr "tbl_df") with 11 columns:
the name of the location ("location"),
the city it is in ("city"),
the code of country it is in ("country"),
its longitude ("longitude") and latitude if available ("latitude"),
the parameter ("parameter")
the value of the measurement ("value")
the last time and date at which the value was updated ("lastUpdated"),
the unit of the measure ("unit")
and finally an URL encoded version of the city name ("cityURL")
and of the location name ("locationURL").
. and two attributes, a meta data.frame (dplyr "tbl_df") with 1 line and 5 columns:
the API name ("name"),
the license of the data ("license"),
the website url ("website"),
the queried page ("page"),
the limit on the number of results ("limit"),
the number of results found on the platform for the query ("found")
and a timestamp data.frame (dplyr "tbl_df") with the query time and the last time at which the data was modified on the platform.
For queries involving a city or location argument, the URL-encoded name of the city/location (as in cityURL/locationURL), not its name, should be used. You can query any nested combination of country/location/city (level 1, 2 and 3), with only one value for each argument. If you write inconsistent combination such as city="Paris" and country="IN", an error message will be returned. If you write city="Delhi", you do not need to write the code of the country, unless one day there is a city with the same name in another country.
# NOT RUN {
latest_chennai <- aq_latest(country='IN', city='Chennai')
latest_chennai
attr(latest_chennai, "meta")
attr(latest_chennai, "timestamp")
aq_latest(parameter='co')
# }
Run the code above in your browser using DataLab