knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)

version <- as.vector(read.dcf('DESCRIPTION')[, 'Version'])
version <- gsub('-', '.', version)  

strayr

codecov status R build status Lifecycle: superseded

This package has merged with the abscorr package by the R Users' Network for Australian Public Policy. The merged package is called strayr. Find the merged package at runapp's GitHub.

Overview

strayr is a simple tool to wrangle messy Australian state names and/or abbreviations into a consistent format.

Installation

Install from GitHub with:

# if you don't have devtools installed, first run:
# install.packages("devtools")
devtools::install_github("mattcowgill/strayr")

Examples

Let's start with a character vector that includes some misspelled State names, some correctly spelled state names, as well as some abbreviations both malformed and correctly formed.

x <- c("western Straya", "w. A ", "new soth wailes", "SA", "tazz", "Victoria",
       "northn territy")

To convert this character vector to a vector of abbreviations for State names, simply use the strayr() function:

library(strayr)
strayr(x)

If you want full names for the states rather than abbreviations:

strayr(x, to = "state_name")

By default, strayr() uses fuzzy or approximate string matching to match the elements in your character vector to state names/abbreviations. If you only want to permit exact matching, you can disable fuzzy matching. This means you will never get false matches, but you will also fail to match misspelled state names or malformed abbreviations; you'll get an NA if no match can be found.

 strayr(x, fuzzy_match = FALSE)

If your data is in a data frame, strayr() works well within a dplyr::mutate() call:

 x_df <- data.frame(state = x, stringsAsFactors = FALSE)

library(dplyr)
 x_df %>% 
   mutate(state_abbr = strayr(state))

Australian Public Holidays

This package includes the auholidays dataset from the Australian Public Holidays Dates Machine Readable Dataset as well as a helper function is_holiday:

str(auholidays)


is_holiday('2020-01-01')
is_holiday('2019-05-27', jurisdictions=c('ACT', 'TAS'))

h_df <- data.frame(dates = c('2020-01-01', '2020-01-10'))

h_df %>%
  mutate(IsHoliday = is_holiday(dates))


MattCowgill/strayr documentation built on May 31, 2021, 12:15 a.m.