Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/utils_find_correlationtype.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
out$is_continuous <- TRUE
}

if (all(x %% 1 == 0)) {
if (any(!is.na(x)) && all(x %% 1 == 0, na.rm = TRUE)) {

Check warning on line 60 in R/utils_find_correlationtype.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils_find_correlationtype.R,line=60,col=7,[outer_negation_linter] !all(x) is better than any(!x). The former applies negation only once after aggregation instead of many times for each element of x.
out$is_count <- TRUE
}

Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-cor_pairwise_complete_with_NA.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test_that("pairwise complete correlation with missing data works", {
set.seed(345345)
data_set <- data.frame(
a = sample(c(NA, 1:5), 1000, replace = TRUE),
b = sample(c(NA, 1:5), 1000, replace = TRUE)
)

expected_cor <- cor(data_set, use = "pairwise.complete.obs")

got_cor <- correlation::correlation(
data = data_set,
method = "auto",
missing = "keep_pairwise"
)

testthat::expect_equal(got_cor$r, expected_cor[1, 2])

Check warning on line 16 in tests/testthat/test-cor_pairwise_complete_with_NA.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-cor_pairwise_complete_with_NA.R,line=16,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
})
Loading