knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
warning = FALSE,
message = FALSE
)
library(nolaOpenData)
library(dplyr)
library(ggplot2)
Welcome to the nolaOpenData package, an R package
designed to provide convenient access to the New Orleans Open Data
Portal.
The package provides a streamlined interface for discovering and downloading datasets from New Orleans Open Data. It helps bridge the gap between raw Socrata API endpoints and tidy data analysis in R.
The package provides three primary functions:
nola_list_datasets() for browsing available
datasetsnola_pull_dataset() for downloading datasets using a
catalog key or Socrata UIDnola_any_dataset() for downloading data directly from a
Socrata JSON endpointThe first step in a typical workflow is to use
nola_list_datasets() to retrieve the live New Orleans Open
Data catalog.
catalog <- nola_list_datasets()
catalog
The returned catalog includes information about the datasets available through the portal. Two especially important columns are:
key, a human-readable dataset identifier generated from
the dataset nameuid, the official Socrata dataset identifierYou can search the catalog for datasets containing a keyword.
catalog |>
filter(grepl("hiring", name, ignore.case = TRUE)) |>
select(key, uid, name)
Replace hiring with a useful search term related to the
example dataset selected for the package.
The primary way to download data is with
nola_pull_dataset().
A dataset can be requested using either its human-readable catalog key or its official Socrata UID.
example_data_uid <- nola_pull_dataset(
dataset = "wx2k-rsac",
limit = 5
)
example_data_uid
example_data_key <- nola_pull_dataset(
dataset = "city_jobs_hiring_data",
limit = 5
)
example_data_key
Both calls should return data from the same dataset.
Dataset keys are easier to read, while Socrata UIDs are more stable.
For reproducible research and long-term workflows, using the official Socrata UID is generally recommended.
The filters argument can be used for simple exact-match
filtering.
filtered_data <- nola_pull_dataset(
dataset = "wx2k-rsac",
limit = 25,
filters = list(
department = "Safety & Permits"
)
)
filtered_data
You can confirm that the filter worked by inspecting the unique values in the selected field.
filtered_data |>
distinct(department)
Multiple values can also be supplied.
filtered_multiple <- nola_pull_dataset(
dataset = "wx2k-rsac",
limit = 50,
filters = list(
department = c("Safety & Permits", "FIRE")
)
)
filtered_multiple
Multiple fields can be combined within the same filter list.
filtered_combination <- nola_pull_dataset(
dataset = "wx2k-rsac",
limit = 50,
filters = list(
department = "Safety & Permits",
job_title = "BUILDING INSPECTOR SUPERVISOR (CLASS CODE 2214)"
)
)
filtered_combination
If the example dataset contains a date or datetime field, records can
be filtered using from, to, and
date_field.
date_filtered_data <- nola_pull_dataset(
dataset = "wx2k-rsac",
from = "2025-01-01",
to = "2026-01-01",
date_field = "start_date",
limit = 100
)
date_filtered_data
The from date is inclusive, while the to
date is exclusive.
A single day can also be requested using the date
argument.
single_day_data <- nola_pull_dataset(
dataset = "wx2k-rsac",
date = "2025-01-05",
date_field = "start_date",
limit = 100
)
single_day_data
The preferred workflow is to use nola_list_datasets()
together with nola_pull_dataset().
However, when a dataset is not available in the package catalog,
nola_any_dataset() can download data directly from a
Socrata JSON endpoint.
New Orleans Open Data endpoints typically follow this structure:
https://data.nola.gov/resource/<dataset_uid>.json
For example:
https://data.nola.gov/resource/wx2k-rsac.json
The endpoint can then be supplied directly to
nola_any_dataset().
endpoint_data <- nola_any_dataset(
json_link = "https://data.nola.gov/resource/wx2k-rsac.json",
limit = 5
)
endpoint_data
Use nola_pull_dataset() when the dataset is available
through nola_list_datasets().
Use nola_any_dataset() when you already have a valid
Socrata JSON endpoint or when the dataset is not included in the package
catalog.
Once the data have been downloaded, they can be analyzed using standard R tools.
The following example counts the number of records in a categorical field.
category_summary <- nola_pull_dataset(
dataset = "wx2k-rsac",
limit = 500
) |>
filter(!is.na(department)) |>
count(department, sort = TRUE)
category_summary
The results can then be visualized.
category_summary |>
slice_head(n = 10) |>
ggplot(
aes(
x = n,
y = reorder(department, n)
)
) +
geom_col() +
theme_minimal() +
labs(
title = "Most Frequent Categories",
x = "Number of Records",
y = "Category"
)
This example demonstrates the complete workflow from discovering a dataset to downloading, filtering, summarizing, and visualizing it.
The nolaOpenData package provides a consistent interface
for working with data from the New Orleans Open Data Portal.
In this vignette, you learned how to:
nola_list_datasets()nola_pull_dataset()nola_any_dataset()These functions allow users to focus on analysis rather than manually constructing API requests.
If you use this package for research or educational purposes, cite it using the package citation returned by:
citation("nolaOpenData")