coerce: Explicit coercion between State and LGA names

as_stateR Documentation

Explicit coercion between State and LGA names

Description

Takes the names of either States or LGAs and converts them explicitly into objects of the other class.

Usage

as_state(x)

as_lga(x)

Arguments

x

A string representing either States or Local Government Areas (LGAs) that dually name one of these administrative regions.

Details

There are a few LGAs in the country that bear the same name as their State, and this could create some confusion when trying to use some of the the functionalities of this package. The States/LGAs in question are Bauchi, Ebonyi, Ekity, Gombe, Katsina and Kogi.

There as subtle differences in the way these functions handle data for States as against those for LGAs. In the case of States, an object of mode character is the preferred argument; alternatively, an object of class states will serve as long as it has only one element. For LGAs, the string is the preferred argument, since an object constructed with lgas() that is supplied a State's name as argument will list all the LGAs in that State. If a pre-formed lgas object is to be coerced to a states object, it should first be unclassed or explicitly coerced with as.character.

Value

In the case of as_state, an object of class states; with as_lga, an object of class lgas.

Examples

kt.st <- states("Katsina")  # Ensure this is a State, not an LGA.
kt.lg <- suppressWarnings(as_lga(kt.st))
is_state(kt.st)             # TRUE
is_lga(kt.lg)               # TRUE

## Where there's no ambiguity, it doesn't make sense to coerce
## This kind of operation ends with an error
## Not run: 
as_state("Kano")
as_lga("Michika")

## End(Not run)



naijR documentation built on Aug. 8, 2023, 5:13 p.m.