data-raw/put-MEASURE_VARS.R

metadatum <- function(class = "character",
                      permitted_values,
                      q = stop("Mandatory")) {
  defined <- ls()
  passed <- names(as.list(match.call())[-1])

  if (any(!defined %in% passed)) {
    stop(paste("missing values for",
               paste(setdiff(defined, passed),
                     collapse = ", ")))
  }

  list(class = class,
       permitted_values = permitted_values,
       q = q)
}

metadatum_logical <- function(has_na,
                              q = stop("Mandatory")) {
  if (!missing(has_na) && is.na(has_na)) {
    metadatum(class = "logical",
              permitted_values = c(NA, FALSE, TRUE),
              q = q)
  } else {
    metadatum(class = "logical",
              permitted_values = c(FALSE, TRUE),
              q = q)
  }
}

# Measure vars depends on itself; run twice.
MEASURE_VARS <- NULL
for (i in 1:2)
MEASURE_VARS <-
  list("Address1YearAgo" = list(f = function(x) is.character(x),
                                q = 9),
       "Address5YearsAgo" = list(f = function(x) is.character(x),
                                 q = 10),
       "Age" = metadatum(class = c("ordered", "factor"),
                         permitted_values = c("0-4", "5-14",
                                              "0-14",
                                              "15-19", "20-24",
                                              "15-24",
                                              "25-34",
                                              "35-44", "45-54", "55-64",
                                              "65-74",
                                              "75+",
                                              "75-84",
                                              "85+"),
                         q = 4),
       "Age5yr" = metadatum(class = c("ordered", "factor"),
                            permitted_values = c("0-4", "5-9", "10-14",
                                                 "15-19", "20-24", "25-29", "30-34",
                                                 "35-39", "40-44", "45-49", "50-54", "55-59", "60-64", "65-69",
                                                 "65+",
                                                 "70-74", "75-79", "80-84", "85+"),
                            q = 4),
       "Age.min" = metadatum(class = "integer",
                             permitted_values = 0:100,
                             q = 4),
       "AgeChild" = metadatum(class = c("ordered", "factor"),
                              permitted_values =  c("0-4", "5-9", "10-12", "13-14", "15-17",
                                                    "18-20", "21-24"),
                              q = 4),
       "AgeStudent" = metadatum(class = c("ordered", "factor"),
                                permitted_values = c("0-4", "5-14", "15-19", "20-24", "25+"),
                                q = 4),
       "AgedUnder25" = metadatum_logical(NA, q = 4),
       "Ancestry" = metadatum(class = "character",
                              permitted_values = c(NA, "Australian", "Australian Aboriginal",
                                                   "Chinese", "Croatian",
                                                   "Dutch", "English", "Filipino", "French",
                                                   "German", "Greek",
                                                   "Hungarian", "Indian", "Irish", "Italian",
                                                   "Korean", "Lebanese",
                                                   "Macedonian", "Maltese", "Maori", "NZ",
                                                   "(Other)", "Polish",
                                                   "Russian",
                                                   "Samoan",
                                                   "Scottish", "Serbian",
                                                   "South African", "Spanish",
                                                   "Sri Lankan", "Turkish", "Vietnamese",
                                                   "Welsh"),
                              q = 18),
       "AustCitizen" = metadatum_logical(q = 11),
       "BornAust" = metadatum_logical(q = 12),
       "ChildrenEverBorn" = metadatum(class = "integer",
                                      permitted_values = c(NA, 0:6),
                                      q = 32),
       "ChildrenPresent" = metadatum_logical(q = 5),
       "CountryOfBirth" = list(f = function(x) {
         is.character(x) && all(nchar(x) == 3L, na.rm = TRUE)
       },
       q = 12),
       "CoupleFamily" = metadatum_logical(NA, q = 5),
       "Denomination" = metadatum(class = "character",
                                  permitted_values = c(NA, "(Other)", "Australian Aboriginal Traditional", "Other spiritual beliefs",
                                                       "Secular beliefs", "Sikhism", "Anglican", "Assyrian Apostolic", "Baptist",
                                                       "Brethren", "Catholic", "Churches Of Christ", "Eastern Orthodox",
                                                       "Jehovah's Witnesses", "Latter Day Saints", "Lutheran", "Oriental Orthodox",
                                                       "Pentecostal", "Presbyterian Reformed", "Protestant (Other)",
                                                       "Salvation Army", "Seventh Day Adventist", "Uniting Church"),
                                  q = 19),
       "Dwelling" = function(x) stop("Dwelling not a permitted name"),
       "PrivateDwelling" = metadatum_logical(q = 56),
       "DwellingStructure" = metadatum(class = "character",
                                       permitted_values = c(NA,
                                                            "(Other)",
                                                            "Flat/apartment",
                                                            "Semi-detached, row/terrace house, townhouse etc.",
                                                            "Separate house"),
                                       q = 0),
       "DwellingSubtype" = metadatum(class = "character",
                                     permitted_values = c(NA, "Cabin household", "Caravan",
                                                          "House or flat attached to a shop, office, etc",
                                                          "Improvised home, tent sleepers",
                                                          "2 storeys or more",
                                                          "1 or 2 storey block", "3 storey block",
                                                          "4 storey block or more",
                                                          "4-8 storey block",
                                                          "9 or more storey block",
                                                          "Attached to a house", "1 storey"),
                                     q = 0),
       "EduInstitutionType" = metadatum(class = c("ordered", "factor"),
                                        permitted_values = c(NA, "Infants/Primary",
                                                             "Pre-school", "Secondary",
                                                             "Technical or Further Educational Institution",
                                                             "University or other tertiary"),
                                        q = 27:30),
       "EnglishProficiency" = metadatum(class = c("ordered", "factor"),
                                        permitted_values = c(NA,
                                                             "Speaks English not well or not at all",
                                                             "Speaks English well or very well"),
                                         q = 17),
       "FatherLabourForceStatus" = metadatum(class = "character",
                                             permitted_values = MEASURE_VARS$LabourForceStatus$permitted_values,
                                             q = c(5, 34, 44)),
       "FamilyComposition" = metadatum(class = "character",
                                       permitted_values = c("Blended family with no other children present",
                                                            "Blended family with other children present",
                                                            "Intact family with no other children present",
                                                            "Intact family with other children present",
                                                            "Other couple family with other children only",
                                                            "Step family with no other children present",
                                                            "Step family with other children present"),
                                       q = 5),
       "HouseholdComposition" = metadatum(class = "character",
                                          permitted_values = c("Couple family with children",
                                                               "Couple family with no children",
                                                               "Group household", "Lone-person household",
                                                               "One parent family with children",
                                                               "Other family"),
                                          q = 5),
       "FamilyHousehold" = metadatum_logical(q = 5),
       "FatherBornAus" = metadatum_logical(q = c(5, 12)),
       "ForOtherChild" = metadatum_logical(q = c(50)),
       "ForOwnChild" = metadatum_logical(q = 50),
       "FullTime" = metadatum_logical(q = 50),
       "HasChild" = metadatum_logical(q = 5),
       "HasChildren" = function(x) stop("Use HasChild."),
       "HasChildUnder15" = metadatum_logical(q = 5),
       "HasChildrenUnder15" = function(x) stop("Use HasChildUnder15."),
       "HasDependentStudent" = metadatum_logical(q = 5),
       "HasNonDependentChild" = metadatum_logical(q = 5),
       "HomeCensusNight" = metadatum_logical(q = NULL),
       "HoursHousekeeping" = metadatum(class = c("ordered", "factor"),
                                       permitted_values = c("0", "<5", "5-14",
                                                            "15-29", "30+"),
                                       q = 48),
       "IncomeFamily.max" = metadatum(class = "double",
                                      permitted_values = c(NA, 0, 7875, 15750, 21000, 26250, 34125, 42000, 52500, 65625,
                                                           78750, 91875, 105000, 131250, 157500, 183750, 210000, Inf),
                                      q = 33),
       "IncomeHousehold.max"  = metadatum(class = "double",
                                          permitted_values = c(NA, 0, 7875, 15750, 21000, 26250, 34125, 42000, 52500, 65625,
                                                               78750, 91875, 105000, 131250, 157500, 183750, 210000, Inf),
                                          q = 33),
       "IncomeTotPersonal.max" = metadatum(class = "double",
                                           permitted_values = c(NA, 0, 7875, 15750, 21000, 26250, 34125, 42000, 52500, 65625,
                                                                78750, 91875, 105000, 131250, 157500, 183750, 210000, Inf),
                                           q = 33),
       "IncomeTotPersonal.min" = function(x) stop("Don't use."),
       "Indigenous" = metadatum_logical(q = 7),
       "IndigenousStatus" = metadatum(class = "character",
                                      permitted_values = c("Aboriginal", "Torres Strait Islander",
                                                           "Both Aboriginal & Torres Strait Islander", "Non-indigenous"),
                                      q = 7),
       "InternetAccessedFromDwelling" = metadatum_logical(NA, q = 59),
       "Landlord" = metadatum(class = "character",
                              permitted_values = c(NA, "(Other)", "Co-op/church group etc", "Person not in same household",
                                                   "Real estate agent", "State or territory housing authority"),
                              q = 57),
       "MaritalStatus" = metadatum(class = "character",
                                   permitted_values = c("Married", "Never married", "Divorced", "Separated", "Widowed"),
                                   q = 5),
       "MaxSchoolingCompleted" = metadatum(class = c("ordered", "factor"),
                                           permitted_values = c("Did not go to school",
                                                                "Year 8 or below",
                                                                "Year 8",
                                                                "Year 9",
                                                                "Year 10",
                                                                "Year 11",
                                                                "Year 12"),
                                           q = 27:30),
       "MortgageRepayment.min" = metadatum(class = "integer",
                                           permitted_values = c(0L, 1800L, 3600L, 5400L, 7200L, 9600L, 12000L, 14400L, 16800L,
                                                                19200L, 21600L, 24000L, 26400L, 28800L, 31200L, 36000L, 48000L,
                                                                60000L),
                                           q = 58),
       "MotherBornAus" = metadatum_logical(q = c(5, 12)),

       "MotorVehicles.min" = metadatum(class = "integer",
                                       permitted_values = c(NA, 0L, 1L, 2L, 3L, 4L),
                                       q = 54),
       "NeedsAssistance" = metadatum_logical(NA, q = 20:24),
       "NumberBedrooms.min" = metadatum(class = "integer",
                                        permitted_values = c(NA, 0L, 1L, 2L, 3L, 4L, 5L, 6L),
                                        q = 55),
       "OnlyEnglishSpokenHome" = metadatum_logical(q = 17),
       "ParentsBornAus" = metadatum(class = "character",
                                    permitted_values = c(NA, "Both", "Father only", "Mother only", "Neither"),
                                     q = c(5, 12)),
       "ProvidedUnpaidChildcare" = metadatum_logical(NA, q = 50),
       "ProvidedUnpaidDisabilityAssistance"= metadatum_logical(NA, q = 20:24),
       "Registered"= metadatum_logical(NA, q = 5),
       "Religion" = metadatum(class = "character",
                              permitted_values = c("(Other)", "Buddhism", "Christianity", "Hinduism", "Islam",
                                                   "Judaism", "No religion"),
                               q = 19),
       "Rent.min" = metadatum(class = "integer",
                              permitted_values = c(0L, 52L, 3937L, 5250L, 7875L, 10500L, 11812L, 14437L, 18375L, 23625L,
                                                   28875L, 34125L, 39375L, 44625L, 49875L),
                               q = 58),
       "SchoolSector" = metadatum(class = "character",
                                  permitted_values = c(NA, "Catholic", "Government", "Non-government"),
                                  q = 25),
       "Sex" = metadatum(class = "character", permitted_values = c("M", "F"), q = 3),
       "SpeaksEnglishOnly" = metadatum_logical(NA, q = 17),
       "UsualResidence" = metadatum(class = "character",
                                    q = 0,
                                    permitted_values = c("Home",
                                                         "Visitor same SA2",
                                                         "Visitor from ACT",
                                                         "Visitor from NSW",
                                                         "Visitor from NT",
                                                         "Visitor from OT",
                                                         "Visitor from QLD",
                                                         "Visitor from SA",
                                                         "Visitor from TAS",
                                                         "Visitor from VIC",
                                                         "Visitor from WA")),
       "UsualResidents.min" = metadatum(class = "integer",
                                        q = 0,
                                        permitted_values = 1:6),
       "Volunteer" = metadatum_logical(NA, q = 51),
       "YearOfArrival.max" = metadatum(class = "integer",
                                       permitted_values = c(1946:2021),
                                       q = 13),
       "medianMortgageRepayment" = list(f = is.integer,
                                        q = 58),
       "medianRent" = list(f = is.integer,
                           q = 58),
       "medianTotalFamilyIncome" = list(f = is.integer,
                                        q = 33),
       "medianTotalHouseholdIncome" = list(f = is.integer,
                                           q = 33),
       "medianTotalPersonalIncome" = list(f = is.integer,
                                          q = 33),
       Year = list(class = "integer",
                   permitted_values = c("2006",
                                        "2011",
                                        "2016"),
                   q = 0),
       FOE = list(class = "character",
                  permitted_values = c("Agriculture environmental and related studies",
                                       "Architecture and building",
                                       "Creative arts",
                                       "Education",
                                       "Engineering and related technologies",
                                       "Field of study inadequately described",
                                       "Field of study not stated",
                                       "Food hospitality and personal services",
                                       "Health",
                                       "Information technology",
                                       "Management and commerce",
                                       "Mixed field programmes",
                                       "Natural and physical sciences",
                                       "Society and culture"),
                  q = 30),
       LabourForceStatus = list(class = "character",
                                permitted_values = c("Employed (full-time)",
                                                     "Employed (away from work)",
                                                     "Employed (hours worked not stated)",
                                                     "Employed (part-time)",
                                                     "Not in the labour force",
                                                     "Unemployed (looking for full-time work)",
                                                     "Unemployed (looking for part-time work)",
                                                     "Unemployed (looking for work)"),
                                q = c(34, 35, 44, 46, 47)),
       LabourForceStatusFather = metadatum(class = "character",
                                           permitted_values = MEASURE_VARS$LabourForceStatus$permitted_values,
                                           q = c(34, 53)),
       LabourForceStatusMother = metadatum(class = "character",
                                           permitted_values = MEASURE_VARS$LabourForceStatus$permitted_values,
                                           q = c(34, 53)),
       LabourForceStatusParent1 = MEASURE_VARS$LabourForceStatusFather,
       LabourForceStatusParent2 = MEASURE_VARS$LabourForceStatusFather,
       NonSchoolQualification = list(class = c("ordered",
                                               "factor"),
                                     permitted_values = c("Certificate nfd", "Certificate I and II Level",
                                                          "Certificate III and IV Level",
                                                          "Advanced Diploma and Diploma",
                                                          "Bachelor",
                                                          "Graduate Diploma and Graduate Certificate",
                                                          "Postgraduate"),
                                     q = c(28:30)),
       Children = list(class = "integer",
                       permitted_values = 1:4,
                       q = 5),
       TotalFamilyIncome.min = list(class = "integer",
                                    permitted_values = c(-1,
                                                         52,
                                                         7800,
                                                         15600,
                                                         20800,
                                                         26000,
                                                         33800,
                                                         41600,
                                                         52000,
                                                         65000,
                                                         78000,
                                                         91000,
                                                         104000,
                                                         130000,
                                                         156000,
                                                         182000,
                                                         208000),
                                    q = 33),
       FullTimeWorkers = list(class = "integer",
                              permitted_values = 0:2,
                              q = c(34, 35, 44, 46, 47)),
       PartTimeWorkers = list(class = "integer",
                              permitted_values = 0:2,
                              q = c(34, 35, 44, 46, 47)),
       AwayFromWork = list(class = "integer",
                           permitted_values = 0:2,
                           q = c(34, 35, 44, 46, 47)),
       NotWorking = list(class = "integer",
                         permitted_values = 0:2,
                         q = c(34, 35, 44, 46, 47)),
       TenureType = list(class = "character",
                         permitted_values = c("Other tenure type",
                                              "Owned outright",
                                              "Owned with a mortgage",
                                              "Rented Housing co operative community church group",
                                              "Rented Landlord type not stated",
                                              "Rented Other landlord type",
                                              "Rented Person not in same household",
                                              "Rented Real estate agent",
                                              "Rented State or territory housing authority"),
                         q = 56),
       HasDependantStudent = list(class = "logical",
                                  permitted_values = c(FALSE,
                                                       TRUE),
                                  q = 53),
       IndustryOfEmployment = list(class = "character",
                                   permitted_values = c("Accommodation and food services",
                                                        "Administrative and support services",
                                                        "Agriculture forestry and fishing",
                                                        "Arts and recreation services",
                                                        "Construction",
                                                        "Education and training",
                                                        "Electricity gas water and waste services",
                                                        "Financial and insurance services",
                                                        "Health care and social assistance",
                                                        "Information media and telecommunications",
                                                        "Manufacturing",
                                                        "Mining",
                                                        "Other services",
                                                        "Professional scientific and technical services",
                                                        "Public administration and safety",
                                                        "Rental hiring and real estate services",
                                                        "Retail trade",
                                                        "Transport postal and warehousing",
                                                        "Wholesale trade"),
                                   q = 42),
       LanguageSpoken = list(class = "character",
                             permitted_values = c("(Other)",
                                                  "Afrikaans",
                                                  "Arabic",
                                                  "Australian_Indigenous_Languages",
                                                  "Chinese_languages_Bengali",
                                                  "Chinese_languages_Cantonese",
                                                  "Chinese_languages_Mandarin",
                                                  "Chinese_languages_Other",
                                                  "Croatian",
                                                  "Dutch",
                                                  "English",
                                                  "Filipino",
                                                  "French",
                                                  "German",
                                                  "Greek",
                                                  "Hindi",
                                                  "Indonesian",
                                                  "Italian",
                                                  "Japanese",
                                                  "Korean",
                                                  "Macedonian",
                                                  "Persian_includes_Dari",
                                                  "Polish",
                                                  "Punjabi",
                                                  "Russian",
                                                  "Samoan",
                                                  "Serbian",
                                                  "Sinhalese",
                                                  "Spanish",
                                                  "Tagalog",
                                                  "Tamil",
                                                  "Thai",
                                                  "Turkish",
                                                  "Urdu",
                                                  "Vietnamese"),
                             q = 16),
       Occupation = list(class = "character",
                         permitted_values = c("Clerical and administrative workers",
                                              "Community and personal service workers",
                                              "Labourers",
                                              "Machinery operators and drivers",
                                              "Managers",
                                              "Professionals",
                                              "Sales workers",
                                              "Technicians and trades workers"),
                         q = 38:39),
       TotalHouseholdIncome.min = list(class = "integer",
                                       permitted_values = c(-1,
                                                            52,
                                                            7800,
                                                            15600,
                                                            20800,
                                                            26000,
                                                            33800,
                                                            41600,
                                                            52000,
                                                            65000,
                                                            78000,
                                                            104000,
                                                            130000,
                                                            156000,
                                                            208000)),
       SameAddress1YearAgo = metadatum_logical(q = 9),
       SameAddress5YearsAgo = metadatum_logical(q = 10),
       EmploymentStatus = metadatum(class = "character",
                                    permitted_values =  c("Contributing family workers",
                                                          "Employee",
                                                          "Owner managers of incorporated enterprises",
                                                          "Owner managers of unincorporated enterprises",
                                                          "Status in employment not stated",
                                                          NA),
                                    q = c(34:37)),
       HoursWorked.min = metadatum(class = "integer",
                                   permitted_values = c(NA,
                                                        0,
                                                        1,
                                                        16,
                                                        25,
                                                        35,
                                                        40,
                                                        41,
                                                        49),
                                   q = 44),
       ModeTravelToWork = metadatum(class = "character",
                                    permitted_values = c("Bicycle",
                                                         "Bus",
                                                         "Bus and car as driver",
                                                         "Bus and car as passenger",
                                                         "Bus and ferry",
                                                         "Bus and other",
                                                         "Bus and tram includes light rail",
                                                         "Bus and two other methods excludes train",
                                                         "Car as driver",
                                                         "Car as passenger",
                                                         "Did not go to work",
                                                         "Ferry",
                                                         "Method of travel not stated",
                                                         "Motorbike scooter",
                                                         "(Other)",
                                                         "Other three methods",
                                                         "Other two methods",
                                                         "Taxi",
                                                         "Train",
                                                         "Train and bus",
                                                         "Train and car as driver",
                                                         "Train and car as passenger",
                                                         "Train and ferry",
                                                         "Train and other",
                                                         "Train and tram includes light rail",
                                                         "Train and two other methods",
                                                         "Tram includes light rail",
                                                         "Truck",
                                                         "Walked only",
                                                         "Worked at home"),
                                    q = 45),
       NumberModes = metadatum(class = "integer",
                               permitted_values = c(1,
                                                    2,
                                                    3,
                                                    NA),
                               q = 45),
       PublicSector = metadatum_logical(NA, q = 40),
       LevelOfGovt = metadatum(class = "character",
                               permitted_values = c(NA,
                                                    "Local",
                                                    "National",
                                                    "State territory"),
                               q = 40),
       OccupationSubtype = metadatum(class = "character",
                                     permitted_values = c(NA,
                                                          "Arts and media professionals",
                                                          "Automotive and engineering trades workers",
                                                          "Business human resource and marketing professionals",
                                                          "Carers and aides",
                                                          "Chief executives general managers and legislators",
                                                          "Cleaners and laundry workers",
                                                          "Clerical and administrative workers nfd",
                                                          "Clerical and office support workers",
                                                          "Community and personal service workers nfd",
                                                          "Construction and mining labourers",
                                                          "Construction trades workers",
                                                          "Design engineering science and transport professionals",
                                                          "Education professionals",
                                                          "Electrotechnology and telecommunications trades workers",
                                                          "Engineering ICT and science technicians",
                                                          "Factory process workers",
                                                          "Farm forestry and garden workers",
                                                          "Farmers and farm managers",
                                                          "Food preparation assistants",
                                                          "Food trades workers",
                                                          "General clerical workers",
                                                          "Health and welfare support workers",
                                                          "Health professionals",
                                                          "Hospitality retail and service managers",
                                                          "Hospitality workers",
                                                          "Information and Communication Technology ICT professionals",
                                                          "Inquiry clerks and receptionists",
                                                          "Labourers nfd",
                                                          "Legal social and welfare professionals",
                                                          "Machine and stationary plant operators",
                                                          "Machinery operators and drivers nfd",
                                                          "Managers nfd",
                                                          "Mobile plant operators",
                                                          "Numerical clerks",
                                                          "Office managers and program administrators",
                                                          "Other clerical and administrative workers",
                                                          "Other labourers",
                                                          "Other technicians and trades workers",
                                                          "Personal assistants and secretaries",
                                                          "Professionals nfd",
                                                          "Protective service workers",
                                                          "Road and rail drivers",
                                                          "Sales assistants and salespersons",
                                                          "Sales representatives and agents",
                                                          "Sales support workers",
                                                          "Sales workers nfd",
                                                          "Skilled animal and horticultural workers",
                                                          "Specialist managers",
                                                          "Sports and personal service workers",
                                                          "Storepersons",
                                                          "Technicians and trades workers nfd"),
                                     q = 38))


usethis::use_data(MEASURE_VARS, overwrite = TRUE)
HughParsonage/Census2016.spec documentation built on July 16, 2022, 11:40 p.m.