From 0d2ac7a64437a0053765bdf8970575e7008f6e28 Mon Sep 17 00:00:00 2001 From: Jannik Orzek <45204741+jhorzek@users.noreply.github.com> Date: Mon, 5 Jan 2026 13:52:45 +0100 Subject: [PATCH 1/2] Allow for NA in data when checking the data type --- R/utils_find_correlationtype.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/utils_find_correlationtype.R b/R/utils_find_correlationtype.R index b8a74921..0b7d0b27 100644 --- a/R/utils_find_correlationtype.R +++ b/R/utils_find_correlationtype.R @@ -57,8 +57,8 @@ out$is_continuous <- TRUE } - if (all(x %% 1 == 0)) { - out$is_count <- TRUE + if (any(!is.na(x)) && all(x %% 1 == 0, na.rm = TRUE)) { + out$is_count <- TRUE } out From d96ad3e0af24f3dc0051f1af0c688803718bd5ab Mon Sep 17 00:00:00 2001 From: Jannik Orzek Date: Sat, 24 Jan 2026 19:02:57 +0100 Subject: [PATCH 2/2] Added test for missing data when using method = "auto" --- R/utils_find_correlationtype.R | 4 ++-- .../test-cor_pairwise_complete_with_NA.R | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/test-cor_pairwise_complete_with_NA.R diff --git a/R/utils_find_correlationtype.R b/R/utils_find_correlationtype.R index 0b7d0b27..3424a3ed 100644 --- a/R/utils_find_correlationtype.R +++ b/R/utils_find_correlationtype.R @@ -57,8 +57,8 @@ out$is_continuous <- TRUE } - if (any(!is.na(x)) && all(x %% 1 == 0, na.rm = TRUE)) { - out$is_count <- TRUE + if (any(!is.na(x)) && all(x %% 1 == 0, na.rm = TRUE)) { + out$is_count <- TRUE } out diff --git a/tests/testthat/test-cor_pairwise_complete_with_NA.R b/tests/testthat/test-cor_pairwise_complete_with_NA.R new file mode 100644 index 00000000..c5fd32cc --- /dev/null +++ b/tests/testthat/test-cor_pairwise_complete_with_NA.R @@ -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]) +})