Skip to contents

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,
  standalone = TRUE,
  chatty = rlang::is_interactive()
)

Arguments

lookup

character. Lower level area code eg "lsoa", "wd", "lad". Equivalent to the lookup parameter in bounds().

within

character. Higher level area code eg "lad", "cty". Equivalent to the within parameter in bounds().

within_names, within_codes

character. In order to restrict data returned to a specific area, either within_names or within_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 to NULL, which will return the most recent data.

within_year

numeric or character. A specific year for data relating to parameter y, if needed. Defaults to NULL, 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.

standalone

logical. Whether this query is standalone (TRUE) or forms part of a geospatial query (FALSE). In the latter case, this function will try to return a lookup table that contains the appropriate columns for spatial data (boundaries or centroids) to be joined onto.

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.

Value

A tibble

Examples

create_lookup_table("msoa", "lad", "Swindon")
#> # A tibble: 27 × 5
#>    msoa21cd  msoa21nm    msoa21hclnm                    lad24cd   lad24nm
#>    <chr>     <chr>       <chr>                          <chr>     <chr>  
#>  1 E02003230 Swindon 019 Central South & Eastcott       E06000030 Swindon
#>  2 E02003221 Swindon 010 Gorse Hill                     E06000030 Swindon
#>  3 E02003231 Swindon 020 Park North & Park South        E06000030 Swindon
#>  4 E02003229 Swindon 018 Freshbrook North & Grange Park E06000030 Swindon
#>  5 E02003233 Swindon 022 Freshbrook South & Toothill    E06000030 Swindon
#>  6 E02003223 Swindon 012 Rodbourne & Cheney Manor       E06000030 Swindon
#>  7 E02003235 Swindon 024 Lawn & East Wichel             E06000030 Swindon
#>  8 E02003232 Swindon 021 Kingshill & Okus               E06000030 Swindon
#>  9 E02006847 Swindon 026 Mouldon Hill & Oakhurst        E06000030 Swindon
#> 10 E02003218 Swindon 007 Pinehurst                      E06000030 Swindon
#> # ℹ 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 W05001715 Bangor Is-y-Coed          W0600… Wrexh… Wrecsam W10000001 North Wa…
#>  2 W05001714 Acton and Maesydre        W0600… Wrexh… Wrecsam W10000001 North Wa…
#>  3 W05001713 Acrefair North            W0600… Wrexh… Wrecsam W10000001 North Wa…
#>  4 W05001615 Whitford                  W0600… Flint… Sir y … W10000001 North Wa…
#>  5 W05001614 Treuddyn                  W0600… Flint… Sir y … W10000001 North Wa…
#>  6 W05001613 Shotton West              W0600… Flint… Sir y … W10000001 North Wa…
#>  7 W05001612 Shotton East and Shotton… W0600… Flint… Sir y … W10000001 North Wa…
#>  8 W05001611 Saltney Ferry             W0600… Flint… Sir y … W10000001 North Wa…
#>  9 W05001610 Queensferry and Sealand   W0600… Flint… Sir y … W10000001 North Wa…
#> 10 W05001609 Pen-y-ffordd              W0600… Flint… Sir y … W10000001 North Wa…
#> # ℹ 754 more rows