-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 20.5 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
filter(variable == "B01001_001", !str_detect(NAME, "County subdivisions not defined")) %>%
mutate(NAME = gsub(pattern = " Town.*", "", NAME),
NAME = gsub(pattern = " city.*", "", NAME),
NAME = gsub(pattern = " town.*", "", NAME)) %>%
select(GEOID, NAME) %>% rename(muni_name = NAME) %>%
rename_with(., .cols = GEOID, .fn = function(x){paste0('cosub_5y', str_sub(as.character(acs_year),
start = 3, end = 4))})} start = 3, end = 4))})}
acs_name <- function(acs_year){
tidycensus::get_acs(geography = "county subdivision", table = "B01001", year = acs_year, state = 25) %>%
filter(variable == "B01001_001", !str_detect(NAME, "County subdivisions not defined")) %>%
mutate(NAME = gsub(pattern = " Town.*", "", NAME),
NAME = gsub(pattern = " city.*", "", NAME),
NAME = gsub(pattern = " town.*", "", NAME)) %>%
select(GEOID, NAME) %>% rename(muni_name = NAME) %>%
rename_with(., .cols = GEOID, .fn = function(x){paste0('cosub_5y', str_sub(as.character(acs_year),
start = 3, end = 4))})}
acs_name(acs_year = 2020)
all_muni_data_keys <- read_csv("data-raw/muni_data_keys_new.csv") %>%
left_join(acs_name(acs_year = 2020)) %>%
select(muni_id, muni_name, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) %>% arrange(muni_id)
library(tidyverse)
acs_name <- function(acs_year){
tidycensus::get_acs(geography = "county subdivision", table = "B01001", year = acs_year, state = 25) %>%
filter(variable == "B01001_001", !str_detect(NAME, "County subdivisions not defined")) %>%
mutate(NAME = gsub(pattern = " Town.*", "", NAME),
NAME = gsub(pattern = " city.*", "", NAME),
NAME = gsub(pattern = " town.*", "", NAME)) %>%
select(GEOID, NAME) %>% rename(muni_name = NAME) %>%
rename_with(., .cols = GEOID, .fn = function(x){paste0('cosub_5y', str_sub(as.character(acs_year),
start = 3, end = 4))})}
acs_name(acs_year = 2020)
all_muni_data_keys <- read_csv("data-raw/muni_data_keys_new.csv") %>%
left_join(acs_name(acs_year = 2020)) %>%
select(muni_id, muni_name, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) %>% arrange(muni_id)
census_muni_keys <- all_muni_data_keys %>% select(muni_id, muni_name, starts_with("cosub"))
community_type <- all_muni_data_keys %>% select(muni_id, muni_name, cmtyp08_id, cmtyp08, cmsbt08_id, cmsbt08)
rpa_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rpa_id, rpa_acr, rpa_name, rpa_alt)
mapc_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, mapc, mmc, nsc, subrg_id, subrg_nm, subrg_acr, subrg_alt)
mbta_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rta_acr, rta_name, mbta, mbta14, mbta51, mbta_other, mbta_cmtyp)
# 2010 Geographies
census_xw_bl10 <- read_csv("data-raw/bl10_2020xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl10_id = geoid10) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_bg10 <- read_csv("data-raw/bg10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct10 <- read_csv("data-raw/ct10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_mu <- read_csv("data-raw/muni_2020xw.csv") %>% select(!seq_id) %>%
janitor::clean_names() %>%
rename(muni_name = basename,
cosub_cn10 = geoid_2010,
cosub_cn20 = geoid_2020,
huch1020p = huch1020pc)
# 2020 Geographies
census_xw_bl20 <- read_csv("data-raw/bl20_2010xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl20_id = geoid20) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_bg20 <- read_csv("data-raw/bg20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct20 <- read_csv("data-raw/ct20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
geog_xw_2010 <- read_csv("data-raw/2010_block_to_geo_crosswalk.csv")
geog_xw_2020 <- read_csv("data-raw/2020_block_to_geo_crosswalk.csv")
usethis::use_data(census_muni_keys, all_muni_data_keys, community_type, rpa_data_keys, mapc_data_keys, mbta_data_keys,
census_xw_bl10, census_xw_bg10, census_xw_ct10,
census_xw_bl20, census_xw_bg20, census_xw_ct20,
geog_xw_2010, geog_xw_2020, census_xw_mu,
overwrite = TRUE)
all_muni_data_keys
all_muni_data_keys <- read_csv("data-raw/muni_data_keys_new.csv") %>%
left_join(acs_name(acs_year = 2020)) %>%
select(muni_id, muni_name, cosub_5y20, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) %>% arrange(muni_id)
library(tidyverse)
acs_name <- function(acs_year){
tidycensus::get_acs(geography = "county subdivision", table = "B01001", year = acs_year, state = 25) %>%
filter(variable == "B01001_001", !str_detect(NAME, "County subdivisions not defined")) %>%
mutate(NAME = gsub(pattern = " Town.*", "", NAME),
NAME = gsub(pattern = " city.*", "", NAME),
NAME = gsub(pattern = " town.*", "", NAME)) %>%
select(GEOID, NAME) %>% rename(muni_name = NAME) %>%
rename_with(., .cols = GEOID, .fn = function(x){paste0('cosub_5y', str_sub(as.character(acs_year),
start = 3, end = 4))})}
acs_name(acs_year = 2020)
all_muni_data_keys <- read_csv("data-raw/muni_data_keys_new.csv") %>%
left_join(acs_name(acs_year = 2020)) %>%
select(muni_id, muni_name, cosub_5y20, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) %>% arrange(muni_id)
census_muni_keys <- all_muni_data_keys %>% select(muni_id, muni_name, starts_with("cosub"))
community_type <- all_muni_data_keys %>% select(muni_id, muni_name, cmtyp08_id, cmtyp08, cmsbt08_id, cmsbt08)
rpa_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rpa_id, rpa_acr, rpa_name, rpa_alt)
mapc_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, mapc, mmc, nsc, subrg_id, subrg_nm, subrg_acr, subrg_alt)
mbta_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rta_acr, rta_name, mbta, mbta14, mbta51, mbta_other, mbta_cmtyp)
# 2010 Geographies
census_xw_bl10 <- read_csv("data-raw/bl10_2020xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl10_id = geoid10) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_bg10 <- read_csv("data-raw/bg10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct10 <- read_csv("data-raw/ct10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_mu <- read_csv("data-raw/muni_2020xw.csv") %>% select(!seq_id) %>%
janitor::clean_names() %>%
rename(muni_name = basename,
cosub_cn10 = geoid_2010,
cosub_cn20 = geoid_2020,
huch1020p = huch1020pc)
# 2020 Geographies
census_xw_bl20 <- read_csv("data-raw/bl20_2010xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl20_id = geoid20) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_bg20 <- read_csv("data-raw/bg20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct20 <- read_csv("data-raw/ct20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
geog_xw_2010 <- read_csv("data-raw/2010_block_to_geo_crosswalk.csv")
geog_xw_2020 <- read_csv("data-raw/2020_block_to_geo_crosswalk.csv")
usethis::use_data(census_muni_keys, all_muni_data_keys, community_type, rpa_data_keys, mapc_data_keys, mbta_data_keys,
census_xw_bl10, census_xw_bg10, census_xw_ct10,
census_xw_bl20, census_xw_bg20, census_xw_ct20,
geog_xw_2010, geog_xw_2020, census_xw_mu,
overwrite = TRUE)
census_xw_ct10
devtools::document()
usethis::use_package_doc()
devtools::install()
mapcdatakeys::
mapcdatakeys::all_muni_data_keys
.rs.restartR()
devtools::document()
devtools::install()
mapcdatakeys::all_muni_data_keys
devtools::document()
devtools::install()
data-raw/2010_block_to_geo_crosswalk.csv
read_csv("data-raw/2010_block_to_geo_crosswalk.csv")
library(tidyverse)
read_csv("data-raw/2010_block_to_geo_crosswalk.csv")
read_csv("data-raw/2020_block_to_geo_crosswalk.csv")
load("D:/Work/00_MAPC/mapcdatakeys/data/geog_xw_2010.rda")
geog_xw_2010 %>% write_csv("data-raw/2010_block_to_geo_crosswalk.csv")
geog_xw_2010 <- read_csv("data-raw/2010_block_to_geo_crosswalk.csv")
library(tidyverse)
acs_name <- function(acs_year){
tidycensus::get_acs(geography = "county subdivision", table = "B01001", year = acs_year, state = 25) %>%
filter(variable == "B01001_001", !str_detect(NAME, "County subdivisions not defined")) %>%
mutate(NAME = gsub(pattern = " Town.*", "", NAME),
NAME = gsub(pattern = " city.*", "", NAME),
NAME = gsub(pattern = " town.*", "", NAME)) %>%
select(GEOID, NAME) %>% rename(muni_name = NAME) %>%
rename_with(., .cols = GEOID, .fn = function(x){paste0('cosub_5y', str_sub(as.character(acs_year),
start = 3, end = 4))})}
acs_name(acs_year = 2020)
all_muni_data_keys <- read_csv("data-raw/muni_data_keys_new.csv") %>%
left_join(acs_name(acs_year = 2020)) %>%
select(muni_id, muni_name, cosub_5y20, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) %>% arrange(muni_id)
census_muni_keys <- all_muni_data_keys %>% select(muni_id, muni_name, starts_with("cosub"))
community_type <- all_muni_data_keys %>% select(muni_id, muni_name, cmtyp08_id, cmtyp08, cmsbt08_id, cmsbt08)
rpa_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rpa_id, rpa_acr, rpa_name, rpa_alt)
mapc_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, mapc, mmc, nsc, subrg_id, subrg_nm, subrg_acr, subrg_alt)
mbta_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rta_acr, rta_name, mbta, mbta14, mbta51, mbta_other, mbta_cmtyp)
# 2010 Geographies
census_xw_bl10 <- read_csv("data-raw/bl10_2020xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl10_id = geoid10) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_bg10 <- read_csv("data-raw/bg10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct10 <- read_csv("data-raw/ct10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_mu <- read_csv("data-raw/muni_2020xw.csv") %>% select(!seq_id) %>%
janitor::clean_names() %>%
rename(muni_name = basename,
cosub_cn10 = geoid_2010,
cosub_cn20 = geoid_2020,
huch1020p = huch1020pc)
# 2020 Geographies
census_xw_bl20 <- read_csv("data-raw/bl20_2010xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl20_id = geoid20) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_bg20 <- read_csv("data-raw/bg20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct20 <- read_csv("data-raw/ct20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
geog_xw_2010 <- read_csv("data-raw/2010_block_to_geo_crosswalk.csv")
geog_xw_2020 <- read_csv("data-raw/2020_block_to_geo_crosswalk.csv")
usethis::use_data(census_muni_keys, all_muni_data_keys, community_type, rpa_data_keys, mapc_data_keys, mbta_data_keys,
census_xw_bl10, census_xw_bg10, census_xw_ct10,
census_xw_bl20, census_xw_bg20, census_xw_ct20,
geog_xw_2010, geog_xw_2020, census_xw_mu,
overwrite = TRUE)
devtools::document()
devtools::install()
mapcdatakeys::geog_xw_2010
library(mapcdatakeys)
mapcdatakeys::all_muni_data_keys %>% select(mpo)
library(tidyverse)
mapcdatakeys::all_muni_data_keys %>% select(mpo)
load("C:/Users/gately/Downloads/all_muni_data_keys.rda")
all_muni_data_keys %>% select(mpo)
library(tidyverse)
all_muni_data_keys %>% select(mpo)
all_muni_data_keys %>% names()
?use_data
debugSource("~/mapcdatakeys/data-raw/muni_data_keys.R")
gc()
source("~/mapcdatakeys/data-raw/muni_data_keys.R")
devtools::check(document=FALSE)
devtools::install()
mapcdatakeys::all_muni_data_keys %>% select(mpo)
load("C:/Users/gately/Downloads/all_muni_data_keys (1).rda")
View(all_muni_data_keys)
source("~/mapcdatakeys/data-raw/muni_data_keys.R")
getwd()
debugSource("~/mapcdatakeys/data-raw/muni_data_keys.R")
source("~/mapcdatakeys/data-raw/muni_data_keys.R")
str(all_muni_data_keys)
library(usethis)
library(roxygen2)
library(devtools)
library(tidyverse)
acs_name <- function(acs_year){
tidycensus::get_acs(geography = "county subdivision", table = "B01001", year = acs_year, state = 25, cache_table = T) %>%
filter(variable == "B01001_001", !str_detect(NAME, "County subdivisions not defined")) %>%
mutate(NAME = gsub(pattern = " Town.*", "", NAME),
NAME = gsub(pattern = " city.*", "", NAME),
NAME = gsub(pattern = " town.*", "", NAME)) %>%
select(GEOID, NAME) %>% rename(muni_name = NAME) %>%
rename_with(., .cols = GEOID, .fn = function(x){paste0('cosub_5y', str_sub(as.character(acs_year),
start = 3, end = 4))})}
# All Muni Data Keys ------------------------------------------------------
# Parent Table
all_muni_data_keys <-
read_csv("data-raw/muni_data_keys_new.csv") %>%
left_join(acs_name(acs_year = 2020)) %>%
left_join(acs_name(acs_year = 2021)) %>%
select(muni_id, muni_name, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) %>% arrange(muni_id) %>%
#Assigns MPO affiliation to municipalities
mutate(
mpo = case_when(
muni_name == "Hanover" ~ "OCPC",
muni_name == "Stoughton" ~ "OCPC",
muni_name == "Pembroke" ~ "OCPC",
muni_name == "Duxbury" ~ "OCPC",
.default = rpa_acr
),
mpo_name = case_when(
muni_name == "Hanover" ~ "Old Colony Planning Council",
muni_name == "Stoughton" ~ "Old Colony Planning Council",
muni_name == "Pembroke" ~ "Old Colony Planning Council",
muni_name == "Duxbury" ~ "Old Colony Planning Council",
.default = rpa_name
),
mpo_id = case_when(
muni_name == "Hanover" ~ 399,
muni_name == "Stoughton" ~ 399,
muni_name == "Pembroke" ~ 399,
muni_name == "Duxbury" ~ 399,
.default = rpa_id
)#,
# mpo = coalesce(
# mpo,
# rpa_acr
# ),
# mpo_name = coalesce(
# mpo_name,
# rpa_name
# ),
# mpo_id = coalesce(
# mpo_id,
# rpa_id
# )
) |>
select(
-rpa_alt
) |>
relocate(mpo, .after = rpa_acr)
View(all_muni_data_keys)
# All Muni Data Keys ------------------------------------------------------
# Parent Table
all_muni_data_keys <-
read_csv("data-raw/muni_data_keys_new.csv") %>%
left_join(acs_name(acs_year = 2020)) %>%
left_join(acs_name(acs_year = 2021)) %>%
select(muni_id, muni_name, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) %>% arrange(muni_id) %>%
#Assigns MPO affiliation to municipalities
mutate(
mpo = case_when(
muni_name == "Hanover" ~ "OCPC",
muni_name == "Stoughton" ~ "OCPC",
muni_name == "Pembroke" ~ "OCPC",
muni_name == "Duxbury" ~ "OCPC",
.default = rpa_acr
),
mpo_name = case_when(
muni_name == "Hanover" ~ "Old Colony Planning Council",
muni_name == "Stoughton" ~ "Old Colony Planning Council",
muni_name == "Pembroke" ~ "Old Colony Planning Council",
muni_name == "Duxbury" ~ "Old Colony Planning Council",
.default = rpa_name
),
mpo_id = case_when(
muni_name == "Hanover" ~ 399,
muni_name == "Stoughton" ~ 399,
muni_name == "Pembroke" ~ 399,
muni_name == "Duxbury" ~ 399,
.default = rpa_id
)
) |>
select(
-rpa_alt
) |>
relocate(mpo, mpo_name, mpo_id, .after = rpa_name)
View(all_muni_data_keys)
years <- c(2020,2021,2022)
acs_name <- function(acs_year){
tidycensus::get_acs(geography = "county subdivision", table = "B01001", year = acs_year, state = 25, cache_table = T) %>%
filter(variable == "B01001_001", !str_detect(NAME, "County subdivisions not defined")) %>%
mutate(NAME = gsub(pattern = " Town.*", "", NAME),
NAME = gsub(pattern = " city.*", "", NAME),
NAME = gsub(pattern = " town.*", "", NAME)) %>%
select(GEOID, NAME) %>% rename(muni_name = NAME) %>%
rename_with(., .cols = GEOID, .fn = function(x){paste0('cosub_5y', str_sub(as.character(acs_year), start = 3, end = 4))})}
muni_data_keys_new <- read_csv("data-raw/muni_data_keys_new.csv")
for (i in years){
tmp <- acs_name(acs_year = i)
muni_data_keys_new <- left_join(
muni_data_keys_new,
tmp,
by = c("muni_name" = "NAME")
)
rm(tmp)
}
View(tmp)
muni_data_keys_new <- read_csv("data-raw/muni_data_keys_new.csv")
for (i in years){
tmp <- acs_name(acs_year = i)
muni_data_keys_new <- left_join(
muni_data_keys_new,
tmp,
by = c("muni_name")
)
rm(tmp)
print(paste0("Finished updating ACS Year Ending in ", i))
}
View(muni_data_keys_new)
all_muni_data_keys <- muni_data_keys_new |>
select(muni_id, muni_name, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) |>
arrange(muni_id)
View(all_muni_data_keys)
# All Muni Data Keys ------------------------------------------------------
# Parent Table
all_muni_data_keys <- muni_data_keys_new |>
select(muni_id, muni_name, starts_with("cosub_5y"), sort(tidyselect::peek_vars())) |>
arrange(muni_id) |>
#Assigns MPO affiliation to municipalities
mutate(
mpo = case_when(
muni_name == "Hanover" ~ "OCPC",
muni_name == "Stoughton" ~ "OCPC",
muni_name == "Pembroke" ~ "OCPC",
muni_name == "Duxbury" ~ "OCPC",
.default = rpa_acr
),
mpo_name = case_when(
muni_name == "Hanover" ~ "Old Colony Planning Council",
muni_name == "Stoughton" ~ "Old Colony Planning Council",
muni_name == "Pembroke" ~ "Old Colony Planning Council",
muni_name == "Duxbury" ~ "Old Colony Planning Council",
.default = rpa_name
),
mpo_id = case_when(
muni_name == "Hanover" ~ 399,
muni_name == "Stoughton" ~ 399,
muni_name == "Pembroke" ~ 399,
muni_name == "Duxbury" ~ 399,
.default = rpa_id
)
) |>
select(
-rpa_alt
) |>
relocate(mpo, mpo_name, mpo_id, .after = rpa_name)
View(all_muni_data_keys)
# Subset Tables which are collections of similarly linked variables
census_muni_keys <- all_muni_data_keys %>% select(muni_id, muni_name, starts_with("cosub"))
community_type <- all_muni_data_keys %>% select(muni_id, muni_name, cmtyp08_id, cmtyp08, cmsbt08_id, cmsbt08)
rpa_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rpa_id, rpa_acr, rpa_name, mpo, mpo_id, mpo_name)
mapc_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, mapc, mmc, nsc, subrg_id, subrg_nm, subrg_acr, subrg_alt)
mbta_data_keys <- all_muni_data_keys %>% select(muni_id, muni_name, rta_acr, rta_name, mbta, mbta14, mbta51, mbta_other, mbta_cmtyp)
# 2010 Geographies ----
#From IPUMS
census_xw_bl10 <- read_csv("data-raw/bl10_2020xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl10_id = geoid10) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
View(census_xw_bl10)
census_xw_bg10 <- read_csv("data-raw/bg10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct10 <- read_csv("data-raw/ct10_2020xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_mu <- read_csv("data-raw/muni_2020xw.csv") %>% select(!seq_id) %>%
janitor::clean_names() %>%
rename(muni_name = basename,
cosub_cn10 = geoid_2010,
cosub_cn20 = geoid_2020,
huch1020p = huch1020pc)
# 2020 Geographies ----
census_xw_bl20 <- read_csv("data-raw/bl20_2010xw.csv") %>%
select(!c(ct_area, weight)) %>% rename(bl20_id = geoid20) %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_bg20 <- read_csv("data-raw/bg20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
census_xw_ct20 <- read_csv("data-raw/ct20_2010xw.csv") %>%
rename(huch1020p = hu_chng_p,
popch1020p = pop_chng_p,
huch1020 = hu_chng,
popch1020 = pop_chng)
# Geographic Crosswalks ----
geog_xw_2010 <- read_csv("data-raw/2010_block_to_geo_crosswalk.csv")
geog_xw_2020 <- read_csv("data-raw/2020_block_to_geo_crosswalk.csv")
View(geog_xw_2020)
# Neighborhood to Municipality Crosswalk ---
nbhd_muni_xw <- read_csv("data-raw/nbhd_muni_xw.csv")
View(nbhd_muni_xw)
# Neighborhood to Municipality Crosswalk ---
nbhd_muni_xw <- read_csv("data-raw/nbhd_muni_xw.csv") |> dplyr::rename(muni_name = muni)
# ZIP Code to Municipality Crosswalk ---
zip_muni_xw <- read_csv("data-raw/zip_muni_xw.csv")
View(zip_muni_xw)
?str_pad()
# ZIP Code to Municipality Crosswalk ---
zip_muni_xw <- read_csv("data-raw/zip_muni_xw.csv") |>
mutate(
zip = str_pad(as.character(zip), width = 5, side = "left", pad = "0")
)
# ~~~ USER INPUT REQUIRED ~~~~ #
# If you define any new or additional tables, please add them to the list below.
usethis::use_data(census_muni_keys, all_muni_data_keys, community_type, rpa_data_keys,
mapc_data_keys, mbta_data_keys, census_xw_bl10, census_xw_bg10,
census_xw_ct10, census_xw_bl20, census_xw_bg20, census_xw_ct20,
geog_xw_2010, geog_xw_2020, census_xw_mu, nbhd_muni_xw, zip_muni_xw,
overwrite = TRUE, internal = FALSE)
#Check for errors in compiling the package
devtools::check(document=FALSE)
#Check for errors in compiling the package
devtools::check(document=FALSE)