Skip to content

basf/rweatherlink

Repository files navigation

rweatherlink

Lifecycle: maturing CRAN status R build status Codecov test coverage

An R client for Weatherlink v2 API

Usage

library("rweatherlink")

Authentication

The api key and api secret are read by default from environmental variables WL_API_KEY and WL_API_SECRET, but you can provide them also in every function call using the api_key= and api_secret= arguments.

Basic usage

For each endpoint we provide convenience wrappers, like

wl_stations()

The full list of endpoints wrappers is:

  • wl_stations() for /stations & stations/{station-ids} endpoints
  • wl_nodes() for /nodes & nodes/{nodes-ids} endpoints
  • wl_sensors() for /sensors & sensors/{sensor-ids} endpoints
  • wl_sensor_activity() for /sensor-activity & sensor-activity/{sensor-ids} endpoints
  • wl_sensor_catalog() for /sensor-catalog endpoint
  • wl_current() for /current/{station-id} endpoint
  • wl_historic() for /historic/{station-id} endpoint

Parser

For each of the listed functions (except wl_sensor_catalog()) we provide (opinionated) convenience parsers, that parse the return value into a nice data.frame. Columns with UTC-dates for timestamps are added, as well as elevation in meters.

The generic function for all objects is wl_parse()

wl_stations() %>% wl_parse()
wl_sensors() %>% wl_parse()

These parsers are in an experimental stage.

Timestamps

wl_historic() needs unix-timestamps as input for start and end. These can be easily generated from POSIXct objects, e.g.

as.integer(Sys.time())
#> [1] 1608050438

gives the timestamp of the current time.

Under the hood

wl_request() is the workhorse of this package.

With it you can query every API endpoint, e.g.

wl_request(endpoint = "stations")

It takes also care of creating the correct api-signature via HMAC, which us handled by wl_params().

Unit tests

To run the full test suite set valid environmental variables WL_API_KEY and WL_API_SECRET and run devtools::test().

Note, that for some tests more than one stations is needed.

Currently, code coverage is very high. wl_nodes is not well covered by the unit tests.

About

An R client for the weatherlink API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages