Skip to contents

Introduction

Data requests to the OIDA API are returned as tibbles. Tibbles are special data structures that allow for lists to be nested within the column of a data frame. The tibble package is required to create and work with tibbles.

#install.packages("tibble")
library(tibble)
vignette(package = "tibble")

Rectangling tibbles

Extracting list elements from a tibble column is informally known as “rectangling.” The process requires patience and vignettes are available for assistance.

#install.packages("tidyr")
#install.packages("dplyr")
#install.packages("repurrrsive")
#load packages
library(tidyr)
library(dplyr)
library(repurrrsive)
#load vignette in help window
vignette("rectangle", package = "tidyr")

Flattening tibbles

A user may choose to work with the tibble or flatten the file to a tabular form like the more traditional and ubiquitous data frame. There are at least two choices: (1) purrr::flatten or (2) jsonlite::flatten.

#install.packages("purrr")
library(purrr)
help("flatten", package = "purrr")
#install.packages("jsonlite")
library(jsonlite)
help("flatten", package = "jsonlite")

Reference

Hadley Wickham and Garret Grolemund (2017). R for Data Science-Tibbles, O’Reilly Media.