Convert raw air quality data published by https://datos.madrid.es/ to a clean data frame.
The original format is hard to interpret:
28;079;4;6;28079004_6_48;2024;04;01;0.3;V;0.3;V;0.3;V;0.3;V;0.3;V;0.3;V;0.3;V;0.4;V;0.4;V;...
madrid.air allows you to convert it to a more readable form:
Station Year Month Day Hour Magnitude Value
1 28079004 2024 4 1 1 CO 0.3
2 28079004 2024 4 1 2 CO 0.3
3 28079004 2024 4 1 3 CO 0.3
...
Both the CSV and TXT formats published by Madrid City Council are supported. Files for all years, back to 2001, are available in these formats.
To install madrid.air from GitHub start the R CMD interface and run the following commands:
install.packages("devtools")
library(devtools)
install_github("nramon/madrid.air")
Both daily and hourly data can be freely downloaded from https://datos.madrid.es/ (also listed in datos.gob.es).
- Daily data is published as one CSV or TXT file per year. For example,
https://datos.madrid.es/dataset/201410-0-calidad-aire-diario/resource/201410-4-calidad-aire-diario-csv/download/201410-4-calidad-aire-diario-csv.csvcontains 2024. The most recent years are published together in a single, regularly updated file whose name includes a timestamp, so use the dataset page to get its current link. - Hourly data is published as one ZIP file per year containing one CSV/TXT file per month. For example,
https://datos.madrid.es/dataset/201200-0-calidad-aire-horario/resource/201200-0-calidad-aire-horario-zip/download/201200-0-calidad-aire-horario-zip.zipcontains 2024.
The file format is described in the official documentation.
See the package documentation for usage instructions and examples:
library(madrid.air)
?madrid.air
?madrid.air.parse
?madrid.air.magnitudes
?madrid.air.stations
Clone the repository and install the R packages needed to run the tests and the linter:
git clone https://github.com/nramon/madrid.air.git
cd madrid.air
make deps
On Debian or Ubuntu some of them need system libraries first. If make deps fails, run:
sudo apt install build-essential libuv1-dev libxml2-dev libcurl4-openssl-dev libssl-dev
Then use the following targets:
make test: run the tests.make lint: check the code style.make check: runR CMD check.make build: build the package.make document: regenerate the documentation inman/. It requires the roxygen2 package, which is only needed if you change the documentation.make data: regenerate the datasets indata/fromdata-raw/. It is only needed after editingdata-raw/.
To provide feedback please use the issue tracker.
See CONTRIBUTING.md.
Copyright (C) 2016 Ramon Novoa ramonnovoa@gmail.com
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.