Skip to content

Commit

Permalink
Fix cnflicts from site rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
BroVic committed Aug 10, 2023
2 parents a3dc49d + ceddd40 commit b60a4db
Show file tree
Hide file tree
Showing 98 changed files with 5,931 additions and 2,782 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
^.*\.Rproj$
^\.vscode$
^\.Rproj\.user$
^data-raw$
^LICENSE\.md$
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.Rproj.user
.Rhistory
inst/doc
.vscode
sandbox
14 changes: 6 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
Package: naijR
Type: Package
Title: Operations to Ease Data Analyses Specific to Nigeria
Version: 0.5.2
Date: 2023-06-14
Version: 0.6.0
Date: 2023-08-07
Depends:
R (>= 3.6),
grDevices,
methods,
graphics,
utils
Imports:
RColorBrewer (>= 1.1.2),
cli (>= 3.6.0),
lifecycle (>= 0.2.0),
mapdata (>= 2.3.0),
maps (>= 3.3.0),
rgdal (>= 1.4.4),
rlang (>= 0.4.0),
sf (>= 1.0.13),
stringi (>= 1.7.6)
Suggests:
ISOcodes,
covr,
here,
jsonlite,
knitr,
purrr,
readxl,
rmarkdown,
sp (>= 1.4.2),
testthat (>= 3.0.0),
tibble,
tidyr,
usethis
Authors@R: person("Victor", "Ordu",
email = "victorordu@outlook.com",
Expand Down
12 changes: 2 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ S3method(print,regions)
S3method(tail,regions)
export(as_lga)
export(as_state)
export(disambiguate_lga)
export(fix_mobile)
export(fix_region)
export(fix_region_manual)
Expand All @@ -23,24 +24,15 @@ export(map_ng)
export(states)
import(mapdata)
import(rlang)
import(sf)
import(stats)
import(utils)
importFrom(RColorBrewer,brewer.pal.info)
importFrom(cli,cli_abort)
importFrom(cli,cli_warn)
importFrom(grDevices,colours)
importFrom(grDevices,palette)
importFrom(graphics,legend)
importFrom(graphics,par)
importFrom(graphics,points)
importFrom(lifecycle,deprecate_soft)
importFrom(lifecycle,deprecate_warn)
importFrom(lifecycle,deprecated)
importFrom(lifecycle,is_present)
importFrom(maps,SpatialPolygons2map)
importFrom(maps,map)
importFrom(maps,map.text)
importFrom(methods,slot)
importFrom(rlang,abort)
importFrom(rlang,as_name)
importFrom(rlang,enexpr)
Expand Down
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# naijR 0.6.0
## New Features:
* Added a new dataset `states_nigeria` for the States of Nigeria.
* Migrated from RGDAL-based spatial data; the `{sf}` package is now the main dependency.
* `map_ng` gained a newly documented argument `plot`, which hitherto was passed internally to `maps::map()` via `...`.
* Added a new function `disambiguate_lga`, which takes a single-element `lgas` object for handling the names of Local Government Areas that are shared between separate States. This function enables the (re)setting of the `State` attribute of such objects; this can be done interactively, where the replicated States' names are presented for selection by users.

## Fixes:
* Improved on the accuracy of LGA naming in the light of spelling mistakes discovered in the earlier reference document.
* Unwanted display of dialogs when fixing LGA names on Windows OS was reversed (suggested by Laura DeCicco).

# naijR 0.5.2
* Quietened a verbose warning introduced via the soon-to-be-retired spatial data packages.

# naijR 0.5.1
* In nested calls with the function `fix_region`, the `lgas` constructor function does not warn if there are spelling mistakes, as this turned out to be a bit confusing when it was used. In earlier versions, warnings persisted even after fixes were applied.
* In carrying out interactive fixes, particularly of LGA spellings, the more familiar and intuitive native Windows messaging and dialog system is used. Works only on Windows machines; on Linux and MacOs, the usual messaging and interaction occurs at the R console.
Expand Down Expand Up @@ -81,3 +95,4 @@
* Added a `NEWS.md` file to track changes to the package.
* Recognise abbreviations of 'Federal Capital Territory' i.e. FCT.
* Disable error-check on character type for `is_state` so it can be used more effectively for functional programming constructs.

173 changes: 173 additions & 0 deletions R/asreg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Source file: asreg.R
#
# Copyright (C) 2019-2023 Victor Ordu.

# Functions for coercion ----
#

#' Explicit coercion between State and LGA names
#'
#' Takes the names of either States or LGAs and converts them explicitly into
#' objects of the other class.
#'
#' @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 \emph{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 \code{character} is the preferred argument; alternatively, an object
#' of class \code{states} will serve as long as it has only one element. For
#' LGAs, the string is the preferred argument, since an object constructed
#' with \code{lgas()} that is supplied a State's name as argument will
#' list all the LGAs in that State. If a pre-formed \code{lgas} object is to be
#' coerced to a \code{states} object, it should first be \code{unclass}ed or
#' explicitly coerced with \code{as.character}.
#'
#' @rdname coerce
#'
#' @param x A string representing either States or Local Government Areas
#' (LGAs) that dually name one of these administrative regions.
#'
#' @return In the case of \code{as_state}, an object of class \code{states};
#' with \code{as_lga}, an object of class \code{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
#' \dontrun{
#' as_state("Kano")
#' as_lga("Michika")
#' }
#'
#'
#' @export
as_state <- function(x)
{
states(.assert_if_coercible(x))
}




#' @rdname coerce
#'
#' @export
as_lga <- function(x) {
new_lgas(.assert_if_coercible(x))
}



#' @importFrom cli cli_abort
.assert_if_coercible <- function(obj)
{
if (is.factor(obj))
obj <- as.character(obj)

if (!is.character(obj))
cli_abort("Expected a character vector")

if (length(obj) > 1L)
cli_abort("To coerce a region with synonyms, use a vector of length 1L")

if (!obj %in% lgas_like_states())
cli_abort("The object does not possess State/LGA synonyms")

if (inherits(obj, "regions")) {
obj <- unclass(obj)
cli::cli_warn("Object was stripped down to mode 'character'")
}

obj
}




## TODO: Export in next MINOR release.
#' Disambiguate Synonymous States and LGAs
#'
#' Some LGAs in Nigeria bear the name of the States to which they belong to.
#' This function will apply an attribute to such an LGA to distinguish it from
#' its State.
#'
#' @details For \code{state}, if it is not provided by the user, an interactive
#' prompt will be presented to the user to select the appropriate state - but
#' only in interactive sessions; if run as a batch command, this function
#' will signal an error.
#'
#' @param lga An object of class \code{lgas} of length \code{1L}.
#' @param state The name of the State to which the LGA is to belong to.
#' @param ... Arguments to be passed to \code{\link[utils]{menu}}.
#'
#' @return The object of class \code{lgas} with the (possibly) modified
#' \code{State} attribute.
#'
#' @importFrom cli cli_abort
#'
#' @export
#'
#' @examples
#' obi.lga <- lgas("Obi") # Warning
#' try(map_ng(obi.lga)) # Error
#'
#' obi.benue <- disambiguate_lga(obi.lga, "Benue")
#' map_ng(obi.benue)
#'
disambiguate_lga <- function(lga, state = NULL, ...)
{
if (!inherits(lga, "lgas"))
cli_abort("Expected an object of class `lgas`")

if (length(lga) > 1L)
cli_abort("Disambiguation is only done for objects with one element")

lgattr <- attr(lga, "State")

if (is.null(state)) {
if (!interactive())
cli_abort("This operation can only be done in interactive mode")

if (length(lgattr) > 1L) {
title <- sprintf("Which State does '%s LGA' belong to?", lga)
opt <- utils::menu(lgattr, title = title, ...)
state <- lgattr[opt]
}
}
attr(lga, "State") <- state

if (isFALSE(.lga_state_is_valid(lga)))
cli_abort("{as.character(lga)} LGA is not in {state} State")

lga
}




## Checks whether the 'State' attribute of and lgas object is actually
## the correct one for that LGA. This function is provided for cases
## where a State attribute is wrongfully enforced on a LGA name. This
## could happen inadvertently when implementing some of these functions.
.lga_state_is_valid <- function(x)
{
stopifnot(exprs = {
is_lga(x)
length(x) == 1L
})
lgastr <- as.character(x)

if (length(lgastr) > 1L)
cli::cli_abort("More than one LGA was provided")

s <- attr(x, "State")
lga.states <- lgas_nigeria$state[lgas_nigeria$lga == lgastr]
s %in% lga.states
}
2 changes: 1 addition & 1 deletion R/fct.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
## Repairs the use of Abuja in a vector that is intended to be States
.fixAbujaFct <- function(x, type = c("full", "abbrev"))
{
stopifnot({any(is_state(x)) && length(unique(x)) > 1L})
stopifnot(exprs = {any(is_state(x)) && length(unique(x)) > 1L})
abj <- "Abuja"

if (!abj %in% x)
Expand Down
4 changes: 4 additions & 0 deletions R/mobile.R → R/fixmob.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Source file: fixmob.R
#
# Copyright (C) 2019-2023 Victor Ordu.

#' Fix mobile numbers
#'
#' Fixes up local mobile phone numbers to a uniform text format.
Expand Down
Loading

0 comments on commit b60a4db

Please sign in to comment.