From b09adb9265eaf66511fa22d7cc8d7ee091619628 Mon Sep 17 00:00:00 2001 From: Mason Garrison Date: Fri, 2 Jan 2026 15:31:53 -0500 Subject: [PATCH 1/6] Update R/checkParents.R Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- R/checkParents.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/checkParents.R b/R/checkParents.R index 807a1987..3be21cfa 100644 --- a/R/checkParents.R +++ b/R/checkParents.R @@ -16,8 +16,8 @@ #' @param personID Character. Column name for individual IDs. #' @param momID Character. Column name for maternal IDs. #' @param dadID Character. Column name for paternal IDs. -#' @param code_male Value representing male sex -#' @param code_female Value representing female sex +#' @param code_male The code value used to represent male sex in the 'sex' column of \code{ped}. +#' @param code_female The code value used to represent female sex in the 'sex' column of \code{ped}. #' #' @return Depending on the value of `repair`, either a list containing validation results or a repaired dataframe is returned. #' @examples From 1da99fae6bb04b3682d0105dfd5c903a5a9714e5 Mon Sep 17 00:00:00 2001 From: Mason Garrison Date: Fri, 2 Jan 2026 15:32:18 -0500 Subject: [PATCH 2/6] Update R/checkParents.R Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- R/checkParents.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/checkParents.R b/R/checkParents.R index 3be21cfa..060553c3 100644 --- a/R/checkParents.R +++ b/R/checkParents.R @@ -107,9 +107,11 @@ checkParentIDs <- function(ped, verbose = FALSE, repair = FALSE, if (!is.null(code_male) && !is.null(code_female)) { validation_results$male_var <- code_male validation_results$female_var <- code_female + validation_results$sex_code_source <- "user_provided_codes" } else { - validation_results$female_var <- mom_results$modal_sex - validation_results$male_var <- dad_results$modal_sex + validation_results$female_var <- mom_results$modal_sex + validation_results$male_var <- dad_results$modal_sex + validation_results$sex_code_source <- "modal_parent_sex" } # Are any parents in both momID and dadID? momdad <- intersect(ped$dadID, ped$momID) From 715abda2b6c9d0d0da58b9a254a0f27a0b077b0e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 2 Jan 2026 20:32:53 +0000 Subject: [PATCH 3/6] Initial plan From c0400843ee61e49dd7c55446b9ed39942e26d3c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 2 Jan 2026 20:35:44 +0000 Subject: [PATCH 4/6] Add comprehensive test coverage for code_unknown and recode_unknown parameters Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com> --- tests/testthat/test-checkSex.R | 182 +++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/tests/testthat/test-checkSex.R b/tests/testthat/test-checkSex.R index 335aee62..9c6e0e85 100644 --- a/tests/testthat/test-checkSex.R +++ b/tests/testthat/test-checkSex.R @@ -86,3 +86,185 @@ test_that("Functions handle missing values gracefully", { expect_silent(repairSex(ped_with_na, verbose = FALSE, code_male = "M")) expect_silent(recodeSex(ped_with_na, verbose = FALSE, code_male = "M", code_female = "F")) }) + + +# Test Case 5: Handle code_unknown parameter with explicit value +test_that("recodeSex handles code_unknown parameter when explicitly provided", { + # Create pedigree with unknown sex codes + ped <- data.frame( + ID = c(1, 2, 3, 4, 5, 6), + sex = c("M", "F", "M", "F", "U", "U"), + dadID = c(NA, NA, 1, 1, NA, NA), + momID = c(NA, NA, 2, 2, NA, NA) + ) + + # Test with code_unknown = "U" + recoded_ped <- recodeSex(ped, + code_male = "M", + code_female = "F", + code_unknown = "U", + recode_male = "Male", + recode_female = "Female", + recode_unknown = "Unknown" + ) + + # Check that unknown codes are recoded correctly + expect_equal(recoded_ped$sex[5], "Unknown") + expect_equal(recoded_ped$sex[6], "Unknown") + expect_equal(recoded_ped$sex[1], "Male") + expect_equal(recoded_ped$sex[2], "Female") +}) + + +# Test Case 6: Handle code_unknown when it's NA (lines 198-199) +test_that("recodeSex handles code_unknown = NA correctly", { + # Create pedigree where NA represents unknown sex + ped <- data.frame( + ID = c(1, 2, 3, 4, 5), + sex = c("M", "F", "M", "F", NA), + dadID = c(NA, NA, 1, 1, NA), + momID = c(NA, NA, 2, 2, NA) + ) + + # Test with code_unknown = NA + recoded_ped <- recodeSex(ped, + code_male = "M", + code_female = "F", + code_unknown = NA, + recode_male = "Male", + recode_female = "Female", + recode_unknown = "Unknown" + ) + + # Check that NA values are recoded to "Unknown" + expect_equal(recoded_ped$sex[5], "Unknown") + expect_equal(recoded_ped$sex[1], "Male") + expect_equal(recoded_ped$sex[2], "Female") +}) + + +# Test Case 7: Infer unknown values from data (lines 200-201) +test_that("recodeSex infers unknown values when code_unknown is not provided", { + # Create pedigree with values that are neither male nor female + ped <- data.frame( + ID = c(1, 2, 3, 4, 5, 6), + sex = c("M", "F", "M", "F", "X", "?"), + dadID = c(NA, NA, 1, 1, NA, NA), + momID = c(NA, NA, 2, 2, NA, NA) + ) + + # Test without code_unknown - should infer "X" and "?" as unknown + recoded_ped <- recodeSex(ped, + code_male = "M", + code_female = "F", + recode_male = "Male", + recode_female = "Female", + recode_unknown = "Unknown" + ) + + # Check that values not in code_male/code_female are recoded to unknown + expect_equal(recoded_ped$sex[5], "Unknown") + expect_equal(recoded_ped$sex[6], "Unknown") + expect_equal(recoded_ped$sex[1], "Male") + expect_equal(recoded_ped$sex[2], "Female") +}) + + +# Test Case 8: Test recode_unknown parameter variations +test_that("recodeSex respects recode_unknown parameter", { + ped <- data.frame( + ID = c(1, 2, 3, 4, 5), + sex = c("M", "F", "M", "F", "U"), + dadID = c(NA, NA, 1, 1, NA), + momID = c(NA, NA, 2, 2, NA) + ) + + # Test with custom recode_unknown value + recoded_ped <- recodeSex(ped, + code_male = "M", + code_female = "F", + code_unknown = "U", + recode_male = "1", + recode_female = "0", + recode_unknown = "9" + ) + + expect_equal(recoded_ped$sex[5], "9") + expect_equal(recoded_ped$sex[1], "1") + expect_equal(recoded_ped$sex[2], "0") +}) + + +# Test Case 9: Test code_unknown with only code_male provided +test_that("recodeSex handles code_unknown with only code_male", { + ped <- data.frame( + ID = c(1, 2, 3, 4), + sex = c("M", "F", "M", "U"), + dadID = c(NA, NA, 1, NA), + momID = c(NA, NA, 2, NA) + ) + + # Test with only code_male and code_unknown + recoded_ped <- recodeSex(ped, + code_male = "M", + code_unknown = "U", + recode_male = "Male", + recode_female = "Female", + recode_unknown = "Unknown" + ) + + # Male should be recoded, unknown should be recoded, F should be inferred as female + expect_equal(recoded_ped$sex[1], "Male") + expect_equal(recoded_ped$sex[2], "Female") + expect_equal(recoded_ped$sex[4], "Unknown") +}) + + +# Test Case 10: Test code_unknown with only code_female provided +test_that("recodeSex handles code_unknown with only code_female", { + ped <- data.frame( + ID = c(1, 2, 3, 4), + sex = c("M", "F", "F", "U"), + dadID = c(NA, NA, NA, NA), + momID = c(NA, NA, NA, NA) + ) + + # Test with only code_female and code_unknown + recoded_ped <- recodeSex(ped, + code_female = "F", + code_unknown = "U", + recode_male = "Male", + recode_female = "Female", + recode_unknown = "Unknown" + ) + + # Female should be recoded, unknown should be recoded, M should be inferred as male + expect_equal(recoded_ped$sex[1], "Male") + expect_equal(recoded_ped$sex[2], "Female") + expect_equal(recoded_ped$sex[4], "Unknown") +}) + + +# Test Case 11: Test numeric codes with code_unknown +test_that("recodeSex handles numeric code_unknown values", { + ped <- data.frame( + ID = c(1, 2, 3, 4, 5), + sex = c(1, 0, 1, 0, 9), + dadID = c(NA, NA, 1, 1, NA), + momID = c(NA, NA, 2, 2, NA) + ) + + # Test with numeric codes + recoded_ped <- recodeSex(ped, + code_male = 1, + code_female = 0, + code_unknown = 9, + recode_male = "M", + recode_female = "F", + recode_unknown = "U" + ) + + expect_equal(recoded_ped$sex[5], "U") + expect_equal(recoded_ped$sex[1], "M") + expect_equal(recoded_ped$sex[2], "F") +}) From a907b5f7163657e5a810e73f29b91c25cfbf6c18 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 2 Jan 2026 20:37:40 +0000 Subject: [PATCH 5/6] Address code review feedback: improve documentation and test comments Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com> --- R/checkSex.R | 2 +- tests/testthat/test-checkSex.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/checkSex.R b/R/checkSex.R index 9745060e..9eb8181e 100644 --- a/R/checkSex.R +++ b/R/checkSex.R @@ -24,7 +24,7 @@ #' @param ped A dataframe representing the pedigree data with a 'sex' column. #' @param code_male The current code used to represent males in the 'sex' column. #' @param code_female The current code used to represent females in the 'sex' column. If both are NULL, no recoding is performed. -#' @param code_unknown The current code used to represent unknown +#' @param code_unknown The current code used to represent unknown or ambiguous sex in the 'sex' column. Can be NA to indicate that missing values should be treated as unknown. If NULL and both code_male and code_female are provided, values not matching either will be inferred as unknown. #' @param verbose A logical flag indicating whether to print progress and validation messages to the console. #' @param repair A logical flag indicating whether to attempt repairs on the sex coding. #' @param momID The column name for maternal IDs. Default is "momID". diff --git a/tests/testthat/test-checkSex.R b/tests/testthat/test-checkSex.R index 9c6e0e85..a3ccb5c0 100644 --- a/tests/testthat/test-checkSex.R +++ b/tests/testthat/test-checkSex.R @@ -213,7 +213,7 @@ test_that("recodeSex handles code_unknown with only code_male", { recode_unknown = "Unknown" ) - # Male should be recoded, unknown should be recoded, F should be inferred as female + # Check recoding: M->Male, F->Female (inferred), U->Unknown expect_equal(recoded_ped$sex[1], "Male") expect_equal(recoded_ped$sex[2], "Female") expect_equal(recoded_ped$sex[4], "Unknown") @@ -238,7 +238,7 @@ test_that("recodeSex handles code_unknown with only code_female", { recode_unknown = "Unknown" ) - # Female should be recoded, unknown should be recoded, M should be inferred as male + # Check recoding: F->Female, M->Male (inferred), U->Unknown expect_equal(recoded_ped$sex[1], "Male") expect_equal(recoded_ped$sex[2], "Female") expect_equal(recoded_ped$sex[4], "Unknown") From 27104e241e3ae0f7a21538a222ce87947379fcf1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 2 Jan 2026 20:38:30 +0000 Subject: [PATCH 6/6] Remove brittle line number references from test comments Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com> --- tests/testthat/test-checkSex.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-checkSex.R b/tests/testthat/test-checkSex.R index a3ccb5c0..427d37b4 100644 --- a/tests/testthat/test-checkSex.R +++ b/tests/testthat/test-checkSex.R @@ -116,7 +116,7 @@ test_that("recodeSex handles code_unknown parameter when explicitly provided", { }) -# Test Case 6: Handle code_unknown when it's NA (lines 198-199) +# Test Case 6: Handle code_unknown when it's NA test_that("recodeSex handles code_unknown = NA correctly", { # Create pedigree where NA represents unknown sex ped <- data.frame( @@ -143,7 +143,7 @@ test_that("recodeSex handles code_unknown = NA correctly", { }) -# Test Case 7: Infer unknown values from data (lines 200-201) +# Test Case 7: Infer unknown values from data when code_unknown not provided test_that("recodeSex infers unknown values when code_unknown is not provided", { # Create pedigree with values that are neither male nor female ped <- data.frame(