This post is to announce the arrival of naijR 0.2.2 on CRAN.
New S3 classes
This version of the package introduces the use of an object-oriented style to programming, making available constructors for
lgas objects. To create instances of both classes, we pass a character vector of States or LGAs as appropriate. These constructors are somewhat permissive and do not perform strict accuracy checks. For that we have the functions
Check for LGAs
There are 774 LGAs in the country and they are pivotal to any analytic tasks done with country data. They are also very often misspelt as any dataset taken from the wild would reveal. I have taken the pains to provide authoritative appellation for this tier of governance using government sources. This can be easily inspected in the inbuilt package dataset
The new function
is_lga will scan through a vector to check whether its elements have correctly spelt LGAs. Where poorly spelt ones are found, the function
fix_region can be used to correct this. The method for
lgas objects will attempt to do this automatically using partial matching. For example
> library(naijR) > mylga <- c("Amuwo-Odofin", "Bukuru", "Askira-Uba") > is_lga(mylga)  TRUE FALSE FALSE
Fix mispelt regions
A major addition in the current version is the function
fix_region, which helps a user to repair any misspelt adminstrative regions within a dataset. The function has methods for different kinds of regions i.e. States and Local Government Areas, which are optionally represented as the S3 objects
lgas, respectively. However, the function also has a method for base character vectors, mainly for States, since they are not that many. To repair our vector
my_lga, we will create an
lgas object first and then pass it as an argument to
> fixed <- fix_region(lgas(mylga)) Approximate match(es) not found for the following: * Bukuru Warning message: In lgas(mylga) : One or more elements is not an LGA > fixed  "Amuwo-Odofin" "Bukuru" "Askira/Uba"
Askira-Uba has been corrected to its correct spelling,
Askira/Uba. However, a match could not be found for the element
Bukuru. (Bukuru is actually the name of the headquarters of Jos South LGA of Plateau State). To continue attempting to repair our vector, we run
fix_region in interactive mode
> fixed <- fix_region(lgas(mylga), interactive = TRUE) Approximate match(es) not found for the following: * Bukuru Do you want to repair interactively? (Y/N):
The user is prompted to continue interactively. To continue enter something like
Fixing ‘Bukuru’ Search pattern: buk Select the LGA 1: Bukkuyum 2: Retry 3: Skip 4: Quit
We are searching for options using the search term
buk and only one option was returned i.e.
Bukkuyum. Unfortunately, that’s not the one we are looking for so we will enter
2 and run the search again, by passing only
Selection: 2 Search pattern: bu Select the LGA 1: Buruku 2: Akpabuyo 3: Obubra 4: Obudu 5: Burutu 6: Abuja Municipal Area Council 7: Babura 8: Buji 9: Bunkure 10: Sabuwa 11: Bunza 12: Kabba/Bunu 13: Ijebu East 14: Ijebu North 15: Ijebu North East 16: Ijebu Ode 17: Abua/Odual 18: Tambuwal 19: Bursari 20: Bukkuyum 21: Bungudu 22: Retry 23: Skip 24: Quit
The LGA I wanted to select was
Buruku, so I pick option 1
Selection: 1 Warning message: In lgas(mylga) : One or more elements is not an LGA > fixed  "Amuwo-Odofin" "Buruku" "Askira/Uba" > is_lga(fixed)  TRUE TRUE TRUE
We’ve fixed the LGAs! At this point, any LGAs that could not be fixed can be treated be directly manipulation of the object,
This version of the package provides increased granularity for the Nigeria country map, currently going down to LGA levels.
To know more about drawing Nigeria maps with the package, see the documentation (
?map_ng) or read the vignette.
This version of naijR brings some new functionality to aid with data cleaning and validation of LGA names, as well as LGA level mapping. I would like you to try it out and give me some feedback.