how_many_lgas <- function(state) {
require(naijR)
stopifnot(all(is_state(state)))
cat(sprintf("No. of LGAs in %s State:", state),
length(lgas(state)),
fill = TRUE)
}
how_many_lgas("Sokoto")
how_many_lgas("Ekiti")
is_lga(c("Pankshen", "Pankshin"))
# With coercion
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
if (FALSE) {
as_state("Kano")
as_lga("Michika")
}
Run the code above in your browser using DataLab