knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE
)

enigma vignette

enigma is an R package to search and retrieve data from Enigma.io

Enigma holds government data and provides a really nice set of APIs for data, metadata, and stats on each of the datasets. That is, you can request a dataset itself, metadata on the dataset, and summary statistics on the columns of each dataset.

Installation

Stable version from CRAN

install.packages("enigma")

Or, install development version from GitHub

install.packages("devtools")
devtools::install_github("ropengov/enigma")
library('enigma')

Authentication

Enigma API calls require an API key. Go to your account at https://app.enigma.io/settings/account and your key should be on the left hand side near the bottom. You can either pass in your API key each function call with the key parameter, or save your key as either an R environment variable (use the name ENIGMA_KEY), or an R option (use the name enigmaKey).

Get data

out <- enigma_data(dataset='us.gov.whitehouse.visitor-list', select=c('namelast','visitee_namelast','last_updatedby'))

Some metadata on the results

out$info

Look at the data, first 6 rows for readme brevity

head(out$result)

Statistics on dataset columns

out <- enigma_stats(dataset='us.gov.whitehouse.visitor-list', select='total_people')

Some summary stats

out$result[c('sum','avg','stddev','variance','min','max')]

Frequency details

head(out$result$frequency)

Metadata on datasets

out <- enigma_metadata(dataset='us.gov.whitehouse')

Paths

out$info$paths

Immediate nodes

out$info$immediate_nodes

Children tables

out$info$children_tables[[1]]

Use case: Frequency of flight distances

First, get columns for the air carrier dataset

dset <- 'us.gov.dot.rita.trans-stats.air-carrier-statistics.t100d-market-all-carrier'
head(enigma_metadata(dset)$columns$table[,c(1:4)])

Looks like there's a column called distance that we can search on. We by default for varchar type columns only frequency bake for the column.

out <- enigma_stats(dset, select='distance')
head(out$result$frequency)

Direct dataset download

Enigma provides an endpoint .../export/<datasetid> to download a zipped csv file of the entire dataset.

enigma_fetch() gives you an easy way to download these to a specific place on your machine. And a message tells you that a file has been written to disk.

enigma_fetch(dataset='com.crunchbase.info.companies.acquisition')


rOpenGov/enigma documentation built on May 26, 2019, 7:47 p.m.