Reputation: 1279
I apologise if this is missing the obvious, but I cannot find a way to ask assertive to ignore missing data.
Given the following example based on fictional telephone numbers:
testfile.data <- structure(list(goodtelephones = c("01234 567 890", "07987 654 321",
"08456 234 567"), goodemails = c("[email protected]", "[email protected]",
"[email protected]"), badtelephones = c("01234 567 890",
"", "08456 234 567"), bademails = c("[email protected]", "[email protected]",
"")), .Names = c("goodtelephones", "goodemails", "badtelephones",
"bademails"), class = "data.frame", row.names = c(NA, -3L))
library(assertive)
It was always saying that the columns with missing data are not all postcodes - which I know, because some are missing. Am I missing an argument or some other way to work around this so that it ignores the missing ones?
> is_uk_telephone_number(testfile.data$badtelephones)
01234567890 08456234567
TRUE FALSE TRUE
Upvotes: 1
Views: 287
Reputation: 121077
Well spotted, the assertive
package isn't handling missing values properly in its regex-related functions.
This should return NA
.
is_uk_telephone_number(NA)
## <NA>
## FALSE
I'll get a fix for this a.s.a.p.
If you need an instant fix, overwrite the existing function with
assignInNamespace(
"matches_regex",
function (x, rx, ignore.case = TRUE, ...)
{
call_and_name(
function(x)
{
ifelse(
is.na(x),
NA,
grepl(rx, x, ignore.case = ignore.case, ...)
)
},
x
)
},
"assertive"
)
Upvotes: 2