grunwaldlab / poppr

🌶 An R package for genetic analysis of populations with mixed (clonal/sexual) reproduction
https://grunwaldlab.github.io/poppr
68 stars 26 forks source link

[read.genalex()]: Detect semicolon-separated files and throw error with correct command #252

Open zkamvar opened 2 years ago

zkamvar commented 2 years ago

If a user reads in a genalex file with semicolons instead of commas, they will get the following error:

Error in if (nrow(gena) != ninds) { : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In read.genalex("genalex.csv") : NAs introduced by coercion

This happens in this block:

https://github.com/grunwaldlab/poppr/blob/94c745aa2e6a806a125f48b86f9c07d8b6ec95aa/R/file_handling.r#L213-L236

all.info contains the first two lines of the genalex file, which determines the checks for the number of samples, loci, and populations. If the user uses ; as a separator in the file, but does not specify sep = ";", then all.info remains a two-element vector and ninds becomes missing:

> all.info                                                                            
[[1]]
[1] "9;72;5;10;26;20;11;5;;;;;;;;;;;;"

[[2]]
[1] ";;;Pop 1 ;Pop 2 ;Pop 3 ;Pop 4 ;Pop 5 ;;;;;;;;;;;;"