'Error: Join columns must be present in data error, but columns are separated, tidy, and still having problem

I'm having issues joining a set of columns with a simple inner_join even though all of my data is tidy. Below is the error that I receive and below that I will paste simple samples of my data.

library(tidyverse)
library(janitor)


regions_name = regions %>% select(region, name) 
regions_name$region = as.numeric(regions_name$region)

postcode_clean = postcode %>% clean_names()
#postcode_clean$pr = as.double(postcode_clean$pr)

postcode_province = postcode_clean %>% left_join(y = regions_name, by = c("pr", "region"))
#> Error: Join columns must be present in data.
#> x Problem with `region`.
> dput(head(postcode_clean, 10))
structure(list(pc = structure(c("A0A1A0", "A0A1B0", "A0A1C0", 
"A0A1C0", "A0A1C0", "A0A1C0", "A0A1C0", "A0A1C0", "A0A1E0", "A0A1G0"
), label = "Postal code", format.spss = "A6"), pr = structure(c(10, 
10, 10, 10, 10, 10, 10, 10, 10, 10), label = "Province or territory code", format.spss = "F2.0", display_width = 4L, labels = c(Newfoundland = 10, 
`Prince Edward Island` = 11, `Nova Scotia` = 12, `New Brunswick` = 13, 
Quebec = 24, Ontario = 35, Manitoba = 46, Saskatchewan = 47, 
Alberta = 48, `British Columbia` = 59, Yukon = 60, `Northwest Territories` = 61, 
Nunavut = 62), class = c("haven_labelled", "vctrs_vctr", "double"
)), cs_duid = structure(c(1001144, 1001464, 1001557, 1001557, 
1001557, 1001557, 1001557, 1001557, 1001347, 1001409), label = "Census subdivision unique identifier", format.spss = "F7.0", display_width = 9L)), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"))
> dput(head(regions_name, 10))
structure(list(region = c(1, 35, 24, 59, 48, 46, 47, 12, 13, 
10), name = c("Canada", "Ontario", "Quebec", "British Columbia", 
"Alberta", "Manitoba", "Saskatchewan", "Nova Scotia", "New Brunswick", 
"Newfoundland and Labrador")), row.names = c(NA, -10L), class = c("tbl_df", 
"tbl", "data.frame"), last_updated = structure(1648783776.07826, class = c("POSIXct", 
"POSIXt")))

I don't understand it. I'm not doing anything complicated, yet I am being thrown this error. Any suggestions?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source