Create a lookup table by querying the ONS OpenGeography API
Source:R/create_lookup_table.R
create_lookup_table.Rd
Calls return_lookup_query_info()
and processes the output, returning a
tibble.
Usage
create_lookup_table(
lookup,
within = NULL,
within_names = NULL,
within_codes = NULL,
return_width = c("tidy", "full", "minimal"),
lookup_year = NULL,
within_year = NULL,
country_filter = c("UK|GB|EW|EN|SC|WA", "UK", "GB", "EW", "EN", "SC", "WA"),
option = NULL,
chatty = rlang::is_interactive()
)
Arguments
- lookup
character. Lower level area code eg "lsoa", "wd", "lad". Equivalent to the
lookup
parameter inbounds()
.- within
character. Higher level area code eg "lad", "cty". Equivalent to the
within
parameter inbounds()
.- within_names, within_codes
character. In order to restrict data returned to a specific area, either
within_names
orwithin_codes
must be provided. Otherwise all boundaries within the country at that level will be retrieved. Use place names eg "Essex" to restrict to a certain geographical area. Use ONS area codes eg "W02000103" likewise (this is useful with wards, where there are many that share identical names). A vector of multiple names or codes can be supplied.- return_width
character. How many of the possible columns in the returned table to keep. Options are "tidy", "full" or "minimal".
- lookup_year
numeric or character. A specific year for data relating to parameter
x
, if needed. Defaults toNULL
, which will return the most recent data.- within_year
numeric or character. A specific year for data relating to parameter
y
, if needed. Defaults toNULL
, which will return the most recent data.- country_filter
character. Open Geography datasets are sometimes available just within certain countries. Specify a country code if you want your results restricted to a certain country only - eg "WA" for Wales, "EW" for England and Wales. By default returns all options.
- option
numeric. Defaults to 1, which means that the URL will just be the first one from the list of possible services resulting from the level and year filters above. If this does not give you what you want, you can run the script again with a different option from the list.
- chatty
Boolean. Whether to print feedback on the 'decisions' the function has taken about which table to query. Default
TRUE
when the function is run in an interactive session,FALSE
otherwise.
Examples
create_lookup_table("msoa", "lad", "Swindon")
#> Joining with `by = join_by(msoa21nm)`
#> # A tibble: 27 × 5
#> lad23cd lad23nm msoa21nm msoa21cd msoa21hclnm
#> <chr> <chr> <chr> <chr> <chr>
#> 1 E06000030 Swindon Swindon 020 E02003231 Park North & Park South
#> 2 E06000030 Swindon Swindon 016 E02003227 Walcot East
#> 3 E06000030 Swindon Swindon 003 E02003214 Penhill
#> 4 E06000030 Swindon Swindon 008 E02003219 Broad Blunsdon, South Marston & Wanb…
#> 5 E06000030 Swindon Swindon 009 E02003220 Lower Stratton
#> 6 E06000030 Swindon Swindon 005 E02003216 Upper Stratton
#> 7 E06000030 Swindon Swindon 014 E02003225 Westlea & Shaw
#> 8 E06000030 Swindon Swindon 011 E02003222 Roughmoor
#> 9 E06000030 Swindon Swindon 022 E02003233 Freshbrook South & Toothill
#> 10 E06000030 Swindon Swindon 017 E02003228 Central East & Walcot West
#> # ℹ 17 more rows
create_lookup_table("wd", "sener", lookup_year = 2022, return_width = "full")
#> # A tibble: 764 × 7
#> wd22cd wd22nm ua22cd ua22nm ua22nmw sener22cd sener22nm
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 W05001492 Aethwy W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 2 W05001493 Bodowyr W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 3 W05001494 Bro Aberffraw W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 4 W05001495 Bro'r Llynnoedd W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 5 W05001496 Canolbarth Môn W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 6 W05001497 Cefni W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 7 W05001498 Crigyll W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 8 W05001499 Lligwy W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 9 W05001500 Parc a'r Mynydd W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> 10 W05001501 Seiriol W06000001 Isle of Angl… Ynys M… W10000001 North Wa…
#> # ℹ 754 more rows