The fam file is read with R and the column names are set such that the pheno column is called PHENO. The pheno file is also read, then pruned to only contain IID matching those in the fam file followed by replacing the elements of fam$PHENO with elements from pheno$PHENO where IIDs match. This presents an issue where if the pheno file has less/other samples than the fam file, the PHENO column of the fam file is not completely overwritten. If I understand the code correctly, the fam$PHENO column should be initialized to NA before adding the pheno$PHENO values but this is not currently done. No validation is done and thus there is no warning or way do detect that fam$PHENO is not only the phenotype information from the pheno file but possibly mixed with that from the fam file.
before
fam$PHENO[match(pheno$IID, fam$IID)] <- as.numeric(pheno$PHENO)
should be enough. Or did I misinterpret the code?