Skip to contents

Generic NYC NYPD dataset loader by registry key

Usage

morie_datasets_nyc_nypd_by_key(
  dataset_key,
  year = NULL,
  max_features = NULL,
  offline = TRUE,
  resource_id = NULL,
  paginate = FALSE,
  page_size = 1000L,
  max_pages = 200L,
  mode = c("soda2", "soda3"),
  app_token = NULL
)

Arguments

dataset_key

One of the keys in morie_datasets_nyc_nypd_layers().

year

Optional year filter (server-side SoQL).

max_features

Optional row cap. When paginate = TRUE this is the total cap across walked pages.

offline

If TRUE (default), read the included fixture.

resource_id

Optional Socrata resource id override.

paginate

Logical; if TRUE and offline = FALSE, walk SODA2 $offset in page_size chunks until exhausted or max_features is reached. Default FALSE (single 1,000-row request, matching the historical pre-3OO behaviour).

page_size

Per-page row count when paginating (default 1,000, the unauthenticated SODA2 ceiling).

max_pages

Safety net on paginated walks (default 200 -> up to 200,000 rows without an app_token).

mode

One of "soda2" (default JSON resource endpoint) or "soda3" (SoQL query endpoint). 3AAA dual-mode dispatch.

app_token

Optional Socrata API app token for higher rate limits; passed as the X-App-Token header.

Value

A data.frame.

Examples

df <- morie_datasets_nyc_nypd_by_key("nypd_arrests_ytd", offline = TRUE)
head(df)
#>          arrest_key             arrest_date pd_cd
#> 1 NYPD-YA-SYNTH-001 2025-01-11T00:00:00.000   397
#> 2 NYPD-YA-SYNTH-002 2025-02-12T00:00:00.000   101
#> 3 NYPD-YA-SYNTH-003 2025-03-13T00:00:00.000   259
#> 4 NYPD-YA-SYNTH-004 2025-04-14T00:00:00.000   511
#> 5 NYPD-YA-SYNTH-005 2025-05-15T00:00:00.000   339
#>                           pd_desc ky_cd                      ofns_desc
#> 1                         ROBBERY   105                        ROBBERY
#> 2                       ASSAULT 3   344   ASSAULT 3 & RELATED OFFENSES
#> 3                        MISCHIEF   351 CRIMINAL MISCHIEF & RELATED OF
#> 4 CONTROLLED SUBSTANCE POSSESSION   235                DANGEROUS DRUGS
#> 5              PETIT LARCENY OPEN   341                  PETIT LARCENY
#>     law_code law_cat_cd arrest_boro arrest_precinct jurisdiction_code age_group
#> 1 PL 1601005          F           B              42                 0     18-24
#> 2 PL 1200001          M           M              32                 0     25-44
#> 3 PL 1450005          M           K              75                 0     45-64
#> 4 PL 2210020          V           Q             109                 0     18-24
#> 5 PL 1552510          M           S             120                 0     25-44
#>   perp_sex              perp_race x_coord_cd y_coord_cd latitude longitude
#> 1        M                  BLACK         NA         NA    40.83    -73.92
#> 2        M         BLACK HISPANIC         NA         NA    40.81    -73.95
#> 3        F                  WHITE         NA         NA    40.66    -73.88
#> 4        M         WHITE HISPANIC         NA         NA    40.76    -73.92
#> 5        F ASIAN/PACIFIC ISLANDER         NA         NA    40.59    -74.10
#>   geocoded_column
#> 1              NA
#> 2              NA
#> 3              NA
#> 4              NA
#> 5              NA