Skip to contents

Phase 3AAA. Pulls a slice of any morie_datasets_nyc_nypd_by_key()-resolvable dataset and left-joins its borough + precinct foreign keys against the bundled resolvers (morie_datasets_nyc_boroughs() + morie_datasets_nyc_police_precincts()).

Usage

morie_datasets_nyc_nypd_resolved(
  dataset_key,
  year = NULL,
  max_features = NULL,
  offline = TRUE,
  resource_id = NULL,
  mode = c("soda2", "soda3"),
  paginate = FALSE,
  page_size = 1000L,
  max_pages = 200L,
  app_token = NULL,
  resolvers = c("boro", "precinct", "offense", "law_code")
)

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 bundled fixture.

resource_id

Optional Socrata resource id override.

mode

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

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).

app_token

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

resolvers

Character subset of c("boro", "precinct") to join. Default joins both.

Value

A wide data.frame: NYPD columns first, then prefixed resolver columns.

Details

Auto-detects the borough + precinct columns per dataset:

NYPD datasetboro columnprecinct column
nypd_arrests_historicarrest_boro (M/B/K/Q/S)arrest_precinct
nypd_arrests_ytdarrest_boroarrest_precinct
nypd_complaint_historicboro_nm (UPPER)addr_pct_cd
nypd_complaint_ytdboro_nm (UPPER)addr_pct_cd
nypd_hate_crimespatrol_borough_namecomplaint_precinct_code
nypd_uof_incidents(none directly; precinct only)precinct

Resolver columns prefixed boro_* + precinct_* to avoid collisions. Left-join semantics (row count preserved).

Examples

df <- morie_datasets_nyc_nypd_resolved("nypd_arrests_ytd",
                                         offline = TRUE)
names(df)
#>  [1] "law_book"            "ky_cd"               "pd_cd"              
#>  [4] "arrest_precinct"     "arrest_boro"         "arrest_key"         
#>  [7] "arrest_date"         "pd_desc"             "ofns_desc"          
#> [10] "law_code"            "law_cat_cd"          "jurisdiction_code"  
#> [13] "age_group"           "perp_sex"            "perp_race"          
#> [16] "x_coord_cd"          "y_coord_cd"          "latitude"           
#> [19] "longitude"           "geocoded_column"     "boro_borocode"      
#> [22] "boro_boroname"       "boro_boro_nm"        "boro_shape_area"    
#> [25] "boro_shape_leng"     "precinct_shape_leng" "precinct_shape_area"
#> [28] "offense_ofns_desc"   "offense_pd_desc"     "offense_law_cat_cd" 
#> [31] "law_section"         "law_book_name"       "law_jurisdiction"