ValidatePrimKey: Validate if a data frame column confirms to primary key/ID...

Description Usage Arguments Details Value See Also Examples

View source: R/ValidatePrimKey.R

Description

ValidatePrimKey checks if a column in a data frame confirms to the primary key/ID constraints of absence of duplicates and NULL values. Aberrant records if encountered are returned in the output list.

Usage

1
ValidatePrimKey(x, prim.key)

Arguments

x

A data frame.

prim.key

A character vector indicating the name of the data frame column to be validated for primary key/ID constraints (see Details).

Details

The function checks whether a field(column) in a data frame of PGR passport database confirms to the primary key/ID constraints of absence of duplicates and NULL values. If records with nonconforming values in the column are encountered, they are returned in the output list for rectification.

If multiple fields(columns) are given as a character vector in prim.key field, only the first element will be considered as the primary key/ID field(column).

Cleaning of the data in the input field(column) using the DataClean function with appropriate arguments is suggested before running this function.

It is recommended to run this function and rectify aberrant records in a PGR passport database before creating a KWIC index using the KWIC function.

Value

A list with containing the following components:

message1 Indicates whether duplicated values were encountered in prim.key field(column) of data frame x or not.
Duplicates A data frame of the records with duplicated prim.key values if they were encountered.
message2 Indicates whether NULL values were encountered in prim.key field(column) of data frame x or not.
NullRecords A data frame of the records with NULL prim.key values if they were encountered.

See Also

DataClean, KWIC

Examples

1
2
3
4
5
6
7
8
9
GN <- GN1000
ValidatePrimKey(x=GN, prim.key="NationalID")
## Not run: 
# Show error in case of duplicates and NULL values 
# in the primary key/ID field "NationalID"
GN[1001:1005,] <- GN[1:5,]
GN[1001,3] <- ""
ValidatePrimKey(x=GN, prim.key="NationalID")
## End(Not run)

Example output

sh: 1: wc: Permission denied
sh: 1: cannot create /dev/null: Permission denied
Could not detect number of cores, defaulting to 1.
OK: No duplicated records found in prim.key field
OK: No NULL records found in prim.key field
$message1
[1] "OK: No duplicated records found in prim.key field"

$Duplicates
NULL

$message2
[1] "OK: No NULL records found in prim.key field"

$NullRecords
NULL

ERROR: Duplicated records found in prim.key field
ERROR: NULL records found in prim.key field
$message1
[1] "ERROR: Duplicated records found in prim.key field"

$Duplicates
     CommonName    BotanicalName NationalID     CollNo DonorID OtherID1
2     Groundnut Arachis hypogaea   EC100280         NC ICG5288      NCS
1002  Groundnut Arachis hypogaea   EC100280         NC ICG5288      NCS
3     Groundnut Arachis hypogaea   EC100281    MALIMBA ICG5289         
1003  Groundnut Arachis hypogaea   EC100281    MALIMBA ICG5289         
4     Groundnut Arachis hypogaea   EC100713 EC 100713; ICG5296         
1004  Groundnut Arachis hypogaea   EC100713 EC 100713; ICG5296         
5     Groundnut Arachis hypogaea   EC100715  EC 100715 ICG5298         
1005  Groundnut Arachis hypogaea   EC100715  EC 100715 ICG5298         
      OtherID2 BioStatus            SourceCountry TransferYear
2         NC 5  Landrace United States of America         2004
1002      NC 5  Landrace United States of America         2004
3    EC 100281  Landrace                   Malawi         2004
1003 EC 100281  Landrace                   Malawi         2004
4        STARR  Landrace United States of America         2004
1004     STARR  Landrace United States of America         2004
5        COMET  Landrace United States of America         2004
1005     COMET  Landrace United States of America         2004

$message2
[1] "ERROR: NULL records found in prim.key field"

$NullRecords
     CommonName    BotanicalName NationalID                CollNo  DonorID
1001  Groundnut Arachis hypogaea            Shulamith/ NRCG-14555 ICG-4709
     OtherID1 OtherID2 BioStatus SourceCountry TransferYear primdup
1001          U4-47-12  Landrace        Israel         2014   FALSE

PGRdup documentation built on Feb. 17, 2021, 5:06 p.m.