diff --git a/R/row_count.R b/R/row_count.R index 93f1ebbca..0635688c8 100644 --- a/R/row_count.R +++ b/R/row_count.R @@ -52,7 +52,7 @@ row_count <- function(data, select = NULL, exclude = NULL, count = NULL, - allow_coercion = FALSE, + allow_coercion = TRUE, ignore_case = FALSE, regex = FALSE, verbose = TRUE) { @@ -90,10 +90,10 @@ row_count <- function(data, rowSums(is.na(data)) } else { # comparisons in R using == coerce values into a atomic vector, i.e. - # 2 == "2" is TRUE. If `allow_coercion = TRUE`, we only want 2 == 2 or + # 2 == "2" is TRUE. If `allow_coercion = FALSE`, we only want 2 == 2 or # "2" == "2". to achieve this, we simply compute the comparison on numeric # or non-numeric columns only - if (isTRUE(allow_coercion)) { + if (isFALSE(allow_coercion)) { numeric_columns <- vapply(data, is.numeric, TRUE) if (is.numeric(count)) { data <- data[numeric_columns] diff --git a/man/row_count.Rd b/man/row_count.Rd index cfcb051f1..8e66ba9bb 100644 --- a/man/row_count.Rd +++ b/man/row_count.Rd @@ -9,7 +9,7 @@ row_count( select = NULL, exclude = NULL, count = NULL, - allow_coercion = FALSE, + allow_coercion = TRUE, ignore_case = FALSE, regex = FALSE, verbose = TRUE diff --git a/tests/testthat/test-row_count.R b/tests/testthat/test-row_count.R index 57c7e76ed..46125587b 100644 --- a/tests/testthat/test-row_count.R +++ b/tests/testthat/test-row_count.R @@ -34,7 +34,7 @@ test_that("row_count, allow_coercion match", { c4 = c(2, 3, 7, Inf), stringsAsFactors = FALSE ) - expect_identical(row_count(d_mn, count = 2, allow_coercion = FALSE), c(1, 2, 0, 0)) - expect_identical(row_count(d_mn, count = 2, allow_coercion = TRUE), c(1, 0, 0, 0)) - expect_identical(row_count(d_mn, count = "2", allow_coercion = TRUE), c(0, 2, 0, 0)) + expect_identical(row_count(d_mn, count = 2, allow_coercion = TRUE), c(1, 2, 0, 0)) + expect_identical(row_count(d_mn, count = 2, allow_coercion = FALSE), c(1, 0, 0, 0)) + expect_identical(row_count(d_mn, count = "2", allow_coercion = FALSE), c(0, 2, 0, 0)) })