Skip to content

Commit

Permalink
Merge pull request #38 from BroVic/dev
Browse files Browse the repository at this point in the history
Merge update to 0.4.4
  • Loading branch information
BroVic authored Aug 30, 2022
2 parents 6ded93a + b916d6a commit 2f4bbcc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: naijR
Type: Package
Title: Operations to Ease Data Analyses Specific to Nigeria
Version: 0.4.3
Date: 2022-07-21
Version: 0.4.4
Date: 2022-08-30
Depends:
R (>= 3.6),
grDevices,
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# naijR 0.4.4
## Bug fix:

* `fix_mobile` fails unexpectedly when only `NA` is supplied as argument. This causes practical problems when, for example, it encounters a column with only missing values.

# naijR 0.4.3
* Addressed a build problem related to CRAN submission.

# naijR 0.4.2
* Improved type checking for mapping functionality and better fidelity.

Expand Down
9 changes: 5 additions & 4 deletions R/mobile.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
#'
#' @export
fix_mobile <- function(x) {
if (!is.character(x)) {
if (!is.numeric(x))
stop(sprintf("Objects of type %s are not supported", sQuote(typeof(x))))
if (!is.null(x) && all(is.na(x)) || is.numeric(x))
x <- as.character(x)
}

if (!is.character(x))
stop(sprintf("Objects of type %s are not supported", sQuote(typeof(x))))

# Remove entries that are beyond redemption i.e. too long or too short
# then add a leading '0' if there are 10 digits
# and then remove those that still don't look like local mobile numbers (NG)
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-mobile.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ test_that("Input corner cases are checked", {
err1 <- "Objects of type .+ are not supported"

expect_error(fix_mobile(NULL), err1)
expect_error(fix_mobile(NA), err1)
expect_type(fix_mobile(NA), "character")
expect_identical(fix_mobile(NA), NA_character_)
expect_identical(fix_mobile(c("8034510441", NA))[2], NA_character_)
expect_error(fix_mobile(data.frame(x = c(09012343829, 08132348321))), err1)
expect_error(fix_mobile(), "argument \"x\" is missing, with no default")
})
Expand Down

0 comments on commit 2f4bbcc

Please sign in to comment.