addAnimalsWithNoRelative: Add an NA value for animals with no relative

View source: R/addAnimalsWithNoRelative.R

addAnimalsWithNoRelativeR Documentation

Add an NA value for animals with no relative

Description

This allows kin to be used with setdiff when there are no relatives otherwise an error would occur because kin[['animal_with_no_relative']] would not be found. See the following: in groupAddAssign

Usage

addAnimalsWithNoRelative(kin, candidates)

Arguments

kin

named list of high-kinship relatives, as produced by getAnimalsWithHighKinship, where each name is an animal Id and each value is a character vector of the Ids sharing a kinship value at or above the threshold.

candidates

character vector of IDs of the animals available for use in the group.

Details

available[[i]] <- setdiff(available[[i]], kin[[id]])

Value

The named list of high-kinship relatives (one element per animal Id, each value a character vector of that Id's high-kinship relatives) with an added element set to NA for each candidate that has no relative.

Examples

library(nprcgenekeepr)
qcPed <- nprcgenekeepr::qcPed
ped <- qcStudbook(qcPed,
  minParentAge = 2.0, reportChanges = FALSE,
  reportErrors = FALSE
)
kmat <- kinship(ped$id, ped$sire, ped$dam, ped$gen, sparse = FALSE)
currentGroups <- list(1L)
currentGroups[[1]] <- examplePedigree$id[1:3]
candidates <- examplePedigree$id[examplePedigree$status == "ALIVE"]
threshold <- 0.015625
kin <- getAnimalsWithHighKinship(kmat, ped, threshold, currentGroups,
  ignore = list(c("F", "F")), minAge = 1.0
)
# Filtering out candidates related to current group members
conflicts <- unique(c(
  unlist(kin[unlist(currentGroups)]),
  unlist(currentGroups)
))
candidates <- setdiff(candidates, conflicts)
kin <- addAnimalsWithNoRelative(kin, candidates)
length(kin) # should be 259
kin[["0DAV0I"]] # should have 34 IDs

nprcgenekeepr documentation built on July 26, 2026, 5:06 p.m.