RAQSAPI
A R extension to retrieve EPA Air Quality System Data via the AQS Data Mart API
Install / Use
/learn @USEPA/RAQSAPIREADME
Introduction to the RAQSAPI package
Clinton Mccrowey, physical scientist - US EPA
- EPA Disclaimer
- Introduction
- About the timeliness of AQS Data
- Installing RAQSAPI
- Using The RAQSAPI library
- Acknowledgements
- References
EPA Disclaimer
This software/application was developed by the U.S. Environmental Protection Agency (USEPA). No warranty expressed or implied is made regarding the accuracy or utility of the system, nor shall the act of distribution constitute any such warranty. The USEPA has relinquished control of the information and no longer has responsibility to protect the integrity, confidentiality or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by the USEPA. The USEPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by the USEPA or the United States Government.
<table> <colgroup> <col style="width: 100%" /> </colgroup> <thead> <tr> <th><span style="color:red"> Warning: US EPA’s AQS Data Mart API V2 is currently<br /> in beta phase of development, the API interface has not been finalized.<br /> This means that certain functionality of the API may change or be removed<br /> without notice. As a result, this package is also currently marked as beta and<br /> may also change to reflect any changes made to the Data Mart API or in respect<br /> to improvements in the design, functionality, quality and documentation of<br /> this package. The authors assume no liability for any problems that may occur<br /> as a result of using this package, the Data Mart service, any software,<br /> service, hardware, or user accounts that may utilize this package. </span></th> </tr> </thead> <tbody> </tbody> </table>Introduction
The RAQSAPI package for the R programming environment allows a R
programming environment to connect to and retrieve data from the United
States Environmental Protection Agency’s (US EPA) Air Quality System
(AQS) Data Mart API v2 Air Quality System<sup>1</sup> interface
directly. This package enables the data user to omit legacy challenges
including coercing data from a JSON object to a usable R object,
retrieving multiple years of data, formatting API requests, retrieving
results, handling credentials, requesting multiple pollutant data and
rate limiting data requests. All the basic functionality of the API have
been implemented that are available from the AQS API Data Mart server.
The library connects to AQS Data Mart API via Secure Hypertext Transfer
Protocol (HTTPS) so there is no need to install external ODBC drivers,
configure ODBC connections or deal with the security vulnerabilities
associated with them. Most API functions have a parameter,
return_header, which by default is set to FALSE. If the user decides to
set return_header to TRUE, then that function will return a R
AQS_DATAMART_APIv2 S3 object which is a two item named list.
The first item, ($Header) in the AQS_DATAMART_APIv2 object is a
tibble<sup>2</sup> which contains the header information. The Header
contains status information regarding the request (success/fail), any
applicable error messages returned from the API, if any exist, the URL
used in the request, a date and time stamp noting when request was
received and other useful information. The second item of the
AQS_DATAMART_APIv2 object ($Data) is a tibble which contains the actual
data being requested. For functions with the return_header option set to
FALSE (default) a simple tibble is returned with just the $Data portion
of the request. After each call to the API a five second stall is
invoked to help prevent overloading the Data Mart API server and to
serve as a simple rate limit. [^1]
About the timeliness of AQS Data
EPA’s AQS Datamart API, the service that RAQSAPI retrieves data from, does not host real time (collected now/today) data. If real time data is needed, please use the AirNow API and direct all questions toward real time data there. RAQSAPI does not work with AirNow and cannot retrieve real time data. For more details see section 7.1 of the About AQS Data page<sup>3</sup>.
Installing RAQSAPI
Either install the stable version from CRAN or install the latest development version from GitHub.
Option 1: Installing the stable version from CRAN (preferred method)
install.packages(pkgs="RAQSAPI", dependencies = TRUE )
Option 2: Installing the development version of RAQSAPI (unstable)
[!CAUTION] The development version of RAQSAPI contains code that has not yet been thoroughly been tested and is more likely to contain bugs. It is recommended that the stable CRAN version be installed for production use.
To install the development version of RAQSAPI, first if not already
installed, install the remotes package and its dependencies. Then run
the following in a R environment.
remotes::install_github(repo = "USEPA/raqsapi",
dependencies = TRUE,
upgrade = "always",
build = TRUE,
#optional, set TRUE if the manual is desired,
#requires pandoc
build_manual = FALSE,
build_vignettes = TRUE
)
Using The RAQSAPI library
Load RAQSAPI
after successfully installing the RAQSAPI package, load the RAQSAPI
library:
library(RAQSAPI)
Sign up and setting up user credentials with the RAQSAPI library
If you have not already done so you will need to sign up with AQS Data Mart using aqs_sign_up function, [^2] this function takes one input, “email”, which is a R character object, that represents the email address that you want to use as a user credential to the AQS Data Mart service. After a successful call to aqs_sign_up an email message will be sent to the email address provided with a new Data Mart key which will be used as a credential key to access the Data Mart API. The aqs_sign_up function can also be used to regenerate a new key for an existing user, to generate a new key simply call the aqs_sign_up function with the parameter “email” set to an existing account. A new key will be e-mailed to the account given.
The credentials used to access the Data Mart API service are stored in a
R environment variable that needs to be set every time the RAQSAPI
library is attached or the key is changed. Without valid credentials,
the Data Mart server will reject any request sent to it. The key used
with Data Mart is a key and is not a password, so the RAQSAPI library
does not treat the key as a password; this means that the key is stored
in plain text and there are no attempts to encrypt Data Mart credentials
as would be done for a username and password combination. The key that
is supplied to use with Data Mart is not intended for authentication but
only account monitoring. Each time RAQSAPI is loaded and before using
any of it’s functions use the aqs_credentials [^3] function to enter in
the user credentials so that RAQSAPI can access the AQS Data Mart
server.
(suggested) Use the keyring package to manage credentials
It is highly suggested that use
Related Skills
tmux
339.5kRemote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
blogwatcher
339.5kMonitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.
prd
Raito Bitcoin ZK client web portal.
Unla
2.1k🧩 MCP Gateway - A lightweight gateway service that instantly transforms existing MCP Servers and APIs into MCP servers with zero code changes. Features Docker deployment and management UI, requiring no infrastructure modifications.
