knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library("apiFetch")

The apiFetch package contains an API fetch function for accessing data from the Thenmap API api.thenmap.net. Thenmap is a repository for geographical borders. In this vignette, we will present the functionality of the fetch() function and visualize the borders using the Shiny Application thenmap_viz.

The API

Via the API, geojson data for different geographical entities can be downloaded. The geojson object fetched from the API is converted to a simple features (sf) object. Simply calling fetch() will fetch current national borders. The fetch function has three parameters: date_str, url and contains_date. Here, date_str is given as a string on the form yyyy-MM-dd. The url should be a proper url including http/https (even ftp/ftps is allowed). Lastly, contains_date simply indicates if date_str should be appended to the url.

Usage

Let us say that we are interested in data from 1906-01-20. To obtain a list with the data we call the function fetch(). As a default print method, the first ten objects are displayed.

fetch(date_str = "1906-01-20")

Data can also be fetched from other URL's, e.g. the Swedish counties:

fetch(url = "http://api.thenmap.net/v2/se-4/geo/")

Shiny Application

Now we are going to demonstrate an application of the apiFetch package. Historical as well as current borders can easily be visualized by using the Shiny application thenmap_viz. Run the code below and select the dates 1906-01-20 and 2020-09-01, one at a time, in the Date widget.

# shiny::runGitHub("sofiejorgensen/thenmap_viz", subdir = "thenmap_viz")


hankOlofs/api_fetch documentation built on Oct. 8, 2020, 5:41 a.m.