knitr::opts_chunk$set(
  collapse = TRUE,
  fig.path = "man/figures/README-",
  out.width = "100%",
  comment = ""
)

naijR

An R package on Nigeria and for Nigeria

CRAN status Codecov test coverage R build status Lifecycle: stable Status at rOpenSci Software Peer Review

The goal of naijR is to make it easier for R users to work with data related to Nigeria.

Usage

Some simple operations

Maps

One of the useful aspects of this package is enabling users to plot country and sub-national geo-spatial maps. Currently, only vector-type graphics are supported. To find out more, read the vignette--accessible from within R as follows:

vignette('nigeria-maps', 'naijR')

Administrative Regions

States

To create a list of all the States of the Nigerian Federation, simply call states().

library(naijR, quietly = TRUE)
ss <- states()
head(ss)
cat(sprintf("\n...but Nigeria has %i States.", length(ss)))

States from a given geo-political zone can also be selected:

states(gpz = "ne")  # i.e. North-East

For other capabilities of this function, see ?states().

Local Government Areas

This is a basic example that shows how to very quickly fetch the names of Local Government Areas within a given State:

lgas("Imo")

To list all the LGAs in Nigeria, call the same function without any parameters:

n <- length(lgas())
sprintf("Nigeria has a total of %i Local Government Areas", n)

Want to create a function to check how many LGAs a particular State has?

how_many_lgas <- function(state) {
  n <- length(lgas(state))
  cat(state, "State has", n, "LGAs\n")
}

how_many_lgas("Sokoto")

Working with phone numbers

It is common to come across datasets where phone numbers are wrongly entered or misinterpreted by software like MS Excel. The function fix_mobile() helps with this.

fix_mobile("8032000000")

The function works on vectors; thus an entire column of a table with phone numbers can be quickly processed. Illegible or irreparable numbers are turned into missing values, e.g.

(dat <- data.frame(
  serialno = 1:8,
  phone = c(
    "123456789",
    "0123456789",
    "8000000001",
    "9012345678",
    "07098765432",
    "08123456789",
    "09064321987",
    "O8055577889"
  )
))
fix_mobile(dat$phone)

Installation

To download and install the current stable version of this package from CRAN:

install.packages("naijR")

The development version can be obtained from GitHub with:

``` {r dev-install, eval = FALSE}

install.packages("remotes")

remotes::install_github("BroVic/naijR", dependencies = TRUE, build_vignettes = TRUE) ```

Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



BroVic/naijR documentation built on Jan. 31, 2024, 12:02 a.m.