An R package for getting memphis311 Data

R
housing
memphis
httr
api
code-enforcement
Quickly access Memphis’s 311 dataset API.
Published

March 21, 2024

Intro

Memphis code enforcement data is available in the Service Requests since 2016 dataset from Memphis Data Hub. The memphis311 package was created as a simple way to access the dataset.

You can install the package from github and access it like so:

# devtools::install_github("sj-io/memphis311")
library(memphis311)

get_311

The package currently contains one function, get_311(). There are no default parameters; you can specify a variable for any column in the dataset.

If you do not specify any columns, the package will call for a csv file containing all rows. Note that this will take a long time, as the dataset has over 2 million rows.

service_requests <- get_311(
  department = "code enforcement", 
  creation_date = "2024-03-09",
  request_type = "CE-Substandard,Derelict Struc"
  ) 

dplyr::glimpse(service_requests)
Rows: 20
Columns: 30
$ division            <chr> "Public Works", "Public Works", "Public Works", "P…
$ department          <chr> "CODE ENFORCEMENT", "CODE ENFORCEMENT", "CODE ENFO…
$ group_name          <chr> "MEMPHIS", "MEMPHIS", "MEMPHIS", "MEMPHIS", "MEMPH…
$ category            <chr> "Inspection-Structures", "Inspection-Structures", …
$ ce_category         <chr> "VIOLATION (S)", NA, "VIOLATION (S)", "VIOLATION (…
$ request_type        <chr> "CE-Substandard,Derelict Struc", "CE-Substandard,D…
$ incident_type_id    <chr> "10409", "10409", "10409", "10409", "10409", "1040…
$ incident_number     <chr> "50016200", "50016209", "50016210", "50016211", "5…
$ incident_id         <chr> "50016200", "50016209", "50016210", "50016211", "5…
$ resolution_code     <chr> "JW-RH", NA, "JW-DM", "JW-RH", "CVOID", "JW-RH", "…
$ resolution_summary  <chr> NA, NA, "PROPERTY WILL BE WRITTEN UP FOR CONDEMNAT…
$ summary_1           <chr> "Not Applicable", "Not Applicable", "Not Applicabl…
$ request_status      <chr> "In Progress", "Open", "In Progress", "In Progress…
$ request_priority    <chr> "Low", "Low", "Low", "Low", "Low", "Low", "Low", "…
$ creation_date       <chr> "2024-03-09T07:27:09.000", "2024-03-09T08:02:04.00…
$ reported_date       <chr> "2024-03-09T07:25:00.000", "2024-03-09T08:00:00.00…
$ last_update_date    <chr> "2024-03-09T08:42:43.000", "2024-03-09T08:03:13.00…
$ followup_date       <chr> "2024-05-01T11:00:00.000", "2024-03-23T11:00:00.00…
$ sr_creation_channel <chr> "WEB", "WEB", "WEB", "WEB", "WEB", "WEB", "WEB", "…
$ created_by_user     <chr> "Sa_GISIdentitystore", "Sa_GISIdentitystore", "Sa_…
$ last_updated_by     <chr> "Esri_Anonymous", "Esri_Anonymous", "Esri_Anonymou…
$ parcel_id           <chr> "047008  00010", "048022  00040", "048020  00017",…
$ full_address        <chr> "2155 GOFF AVE", "1596 WILSON ST", "1488 SOUTH AVE…
$ location_1          <chr> "2155 GOFF AVE", "1596 WILSON ST", "1488 SOUTH AVE…
$ address1            <chr> "2155 GOFF AVE", "1596 WILSON ST", "1488 SOUTH AVE…
$ city                <chr> "MEMPHIS", "MEMPHIS", "MEMPHIS", "MEMPHIS", "MEMPH…
$ state               <chr> "Tennessee", "Tennessee", "Tennessee", "Tennessee"…
$ postal_code         <chr> "38114", "38106", "38106", "38106", "38106", "3811…
$ target_block        <chr> "116", "117", "117", "117", "117", "116", "12", "1…
$ location1           <df[,2]> <data.frame[20 x 2]>

Important notes

Any of the columns in the dataset can be selected, but only basic queries are available right now. This means you can call a specific value for a variable (department = "code enforcement"), including a specific date.

For more complex queries, I recommend using the RSocrata package. This package is meant to be a simple way to access Memphis’s code enforcement data.

The main benefits of this package are:

  • The Memphis 311 API url is included in the package.
  • All date columns in the dataset are shortened to YYYY-MM-DD format, so you don’t need to include times.
  • Text columns will make case-insensitive matches, so it will return requests where department is “CODE ENFORCEMENT” or “Code Enforcement”.
  • Columns are sorted into a more logical order than alphabetical. Locations and times are grouped together so more relevant data can quickly be found.

In the future I hope to add more flexibility for querying (especially dates), and helpers for tidying the dataset to find relevant information for housing research.