Skip to content

Commit

Permalink
Merge pull request #229 from csgillespie/master
Browse files Browse the repository at this point in the history
- Minor efficiency gains by replacing `any(is.na())` with `anyNA()` (#229, @csgillespie).
  • Loading branch information
krlmlr committed Apr 17, 2017
2 parents b99a67d + ed423a6 commit a9ac0f2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions R/check-names.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ check_names_df.character <- function(j, x) {
check_needs_no_dim(j)

pos <- safe_match(j, names(x))
if(any(is.na(pos))){
if(anyNA(pos)) {
unknown_names <- j[is.na(pos)]
stopc(pluralise_msg("Unknown column(s): ", unknown_names))
}
Expand All @@ -21,7 +21,7 @@ check_names_df.character <- function(j, x) {
check_names_df.numeric <- function(j, x) {
check_needs_no_dim(j)

if (any(is.na(j))) {
if (anyNA(j)) {
stopc("NA column indexes not supported")
}

Expand All @@ -48,7 +48,7 @@ check_names_df.logical <- function(j, x) {
if (!(length(j) %in% c(1L, length(x)))) {
stopc("Length of logical index vector must be 1 or ", length(x), ", got: ", length(j))
}
if (any(is.na(j))) {
if (anyNA(j)) {
stopc("NA column indexes not supported")
}
seq_along(x)[j]
Expand All @@ -60,7 +60,6 @@ check_needs_no_dim <- function(j) {
}
}


# check_names_before_after ------------------------------------------------

check_names_before_after <- function(j, ...) UseMethod("check_names_before_after")
Expand All @@ -75,7 +74,7 @@ check_names_before_after.character <- function(j, names) {
check_needs_no_dim(j)

pos <- safe_match(j, names)
if(any(is.na(pos))){
if(anyNA(pos)) {
unknown_names <- j[is.na(pos)]
stopc(pluralise_msg("Unknown column(s): ", unknown_names))
}
Expand Down

0 comments on commit a9ac0f2

Please sign in to comment.