Skip to contents

Use postcodes.io to get postcode data

Usage

postcode_data_join(x, var = "postcode", fix_invalid = TRUE)

Arguments

x

A data frame with a column of postcodes, or a vector of postcodes.

var

String or symbol. The name of the variable in the data frame that comprises the postcodes to be submitted. Should be acceptable as a symbol or as a standard string.

fix_invalid

Boolean, default TRUE. Whether to try to fix any postcodes that are not found (potentially because they are terminated codes, or contain typos).

Examples

postcodes <- c("HD1 2UT", "HD1 2UU", "HD1 2UV")
test_df1 <- dplyr::tibble(
  place = paste0("place_", 1:3),
  postcode = postcodes
)
postcode_data_join(test_df1, fix_invalid = TRUE)
#>  The following postcodes are terminated:
#>   HD1 2UT
#>   and have been replaced with these current postcodes:
#>   HD1 2RD
#>  The following postcodes are invalid:
#>   HD1 2UV
#>   and have been replaced with these nearby postcodes:
#>   HD1 2UD
#> # A tibble: 3 × 41
#>   place   postcode new_postcode result_type   quality eastings northings country
#>   <chr>   <chr>    <chr>        <chr>           <int>    <int>     <int> <chr>  
#> 1 place_1 HD1 2UT  HD1 2RD      terminated          1   414639    416430 England
#> 2 place_2 HD1 2UU  HD1 2UU      valid               1   414433    416422 England
#> 3 place_3 HD1 2UV  HD1 2UD      autocompleted       1   414371    416317 England
#> # ℹ 33 more variables: nhs_ha <chr>, longitude <dbl>, latitude <dbl>,
#> #   european_electoral_region <chr>, primary_care_trust <chr>, region <chr>,
#> #   lsoa <chr>, msoa <chr>, incode <chr>, outcode <chr>,
#> #   parliamentary_constituency <chr>, parliamentary_constituency_2024 <chr>,
#> #   admin_district <chr>, parish <chr>, date_of_introduction <chr>,
#> #   admin_ward <chr>, ccg <chr>, nuts <chr>, pfa <chr>,
#> #   admin_district_code <chr>, admin_county_code <chr>, …