Skip to contents

Finds date errors in columns defined in convertDate as dates and converts date strings to Date objects.

Usage

getDateErrorsAndConvertDatesInPed(sb, errorLst)

Arguments

sb

A dataframe containing a table of pedigree and demographic information.

errorLst

object with placeholders for error types found in a pedigree file by qcStudbook through the functions it calls.

Value

A list with the pedigree, sb, and the errorLst with invalid date rows (errorLst$invalidDateRows), a character vector of row numbers (character(0) when all dates are valid). When the dates are converted, sb also gains an exit column.

Details

Every date column is checked on its own and each invalid date is listed by row; the invalid dates become NA in the converted pedigree, and exit dates are calculated and added, unless every original record has an invalid date, in which case the pedigree is returned unchanged.

Examples

library(nprcgenekeepr)
ped <- nprcgenekeepr::pedInvalidDates
ped
#>   id sire  dam sex      birth
#> 1 s1 <NA> <NA>   M 2000-07-18
#> 2 d1 <NA> <NA>   F 2003-04-13
#> 3 s2 <NA> <NA>   M  205-06-19
#> 4 d2 <NA> <NA>   F 2002-16-22
#> 5 o1   s1   d1   F 2015-02-04
#> 6 o2   s1   d2   F 2009-03-17
#> 7 o3   s2   d2   F 2012-04-11
#> 8 o4   s2   d2   M 2008-04-13
errorLst <- getEmptyErrorLst()
colNamesAndErrors <- fixColumnNames(names(ped), errorLst)
names(ped) <- colNamesAndErrors$newColNames
pedAndErrors <- getDateErrorsAndConvertDatesInPed(ped, errorLst)
pedAndErrors$sb
#>   id sire  dam sex      birth exit
#> 1 s1 <NA> <NA>   M 2000-07-18 <NA>
#> 2 d1 <NA> <NA>   F 2003-04-13 <NA>
#> 3 s2 <NA> <NA>   M       <NA> <NA>
#> 4 d2 <NA> <NA>   F       <NA> <NA>
#> 5 o1   s1   d1   F 2015-02-04 <NA>
#> 6 o2   s1   d2   F 2009-03-17 <NA>
#> 7 o3   s2   d2   F 2012-04-11 <NA>
#> 8 o4   s2   d2   M 2008-04-13 <NA>
pedAndErrors$errorLst
#> $failedDatabaseConnection
#> character(0)
#> 
#> $missingColumns
#> character(0)
#> 
#> $invalidDateRows
#> [1] "3" "4"
#> 
#> $suspiciousParents
#> data frame with 0 columns and 0 rows
#> 
#> $femaleSires
#> character(0)
#> 
#> $maleDams
#> character(0)
#> 
#> $sireAndDam
#> character(0)
#> 
#> $duplicateIds
#> character(0)
#> 
#> $invalidIdChars
#> character(0)
#> 
#> $invalidPlaceholderRows
#> character(0)
#> 
#> $changedCols
#> $changedCols$caseChange
#> character(0)
#> 
#> $changedCols$spaceRemoved
#> character(0)
#> 
#> $changedCols$periodRemoved
#> character(0)
#> 
#> $changedCols$underScoreRemoved
#> character(0)
#> 
#> $changedCols$egoToId
#> character(0)
#> 
#> $changedCols$egoidToId
#> character(0)
#> 
#> $changedCols$sireIdToSire
#> character(0)
#> 
#> $changedCols$damIdToDam
#> character(0)
#> 
#> $changedCols$birthdateToBirth
#> character(0)
#> 
#> $changedCols$deathdateToDeath
#> character(0)
#> 
#> $changedCols$recordstatusToRecordStatus
#> character(0)
#> 
#> $changedCols$fromcenterToFromCenter
#> character(0)
#> 
#> $changedCols$geographicoriginToGeographicOrigin
#> character(0)
#> 
#> 
#> attr(,"class")
#> [1] "list"             "nprcgenekeeprErr"