Skip to content

Commit

Permalink
Merge pull request #56 from BroVic/dev
Browse files Browse the repository at this point in the history
Fix issues with R CMD check for R-devel
  • Loading branch information
BroVic authored Jun 14, 2023
2 parents 2aaacdc + 7c98625 commit 6e07519
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.Rproj.user
.Rhistory
inst/doc
naijR.Rproj
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: naijR
Type: Package
Title: Operations to Ease Data Analyses Specific to Nigeria
Version: 0.5.2
Date: 2023-06-13
Date: 2023-06-14
Depends:
R (>= 3.6),
grDevices,
Expand Down
60 changes: 22 additions & 38 deletions R/map-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -689,53 +689,37 @@ new_shpfile_props <- function(dir, layer, namefield, spObj)


## Fetch the namefield
## This is a generic function. The methods we have are for distinguishing
## how namefields are retrieved, since this varies depending on the kind
## of region passed. The interesting case in point is when getting this
## field for LGA regions, since the spatial data also contains data on
## States. To avoid confusion, when iterating through the data frame, when
## a column with States is encountered it is skipped as can be seen in the
## `.fetch_namefield.lgas` method.
.fetch_namefield <- function(x, ...)
UseMethod(".fetch_namefield")




.fetch_namefield.lgas <- function(x, dt) {
nmfld <- NA
.fetch_namefield <- function(x, dt) {
getfield <- function(index) names(dt)[[index]]
stopifnot(is.data.frame(dt))
nmfield <- NA

for (i in seq_len(ncol(dt))) {
icolumn <- dt[[i]]
iregions <- x %in% icolumn

if (all(unique(dt[[i]]) %in% states())) # skip column with States
next

if (any(x %in% dt[[i]])) { # just any LGAs will do, since some of them
nmfld <- colnames(dt)[i] # also share names with their State
if (inherits(x, "states") && all(iregions)) {
nmfield <- getfield(i)
break
}
}

nmfld
}




.fetch_namefield.states <- function(x, dt) {
# dt[[1]][dt[[1]] == "Nasarawa"] <- "Nassarawa" # Fix for 'ng_admin'
nmfld <- NA

for (i in seq_len(ncol(dt))) {

if (all(x %in% dt[[i]])) { # all MUST be states
nmfld <- colnames(dt)[i]
break
if (inherits(x, "lgas")) {
# skip datafrane column with States
if (all(unique(icolumn) %in% states()))
next

# just any LGAs will do, as some are synonymous with States
if (any(iregions)) {
nmfield <- getfield(i)
break
}
}

}

nmfld
if (is.null(nmfield) || is.na(nmfield))
cli::cli_abort("Problem retrieving the namefield")

nmfield
}


Expand Down
19 changes: 19 additions & 0 deletions naijR.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --resave-data
PackageCheckArgs: --no-tests

0 comments on commit 6e07519

Please sign in to comment.