Error in if (popLoc[1] == 3) { : missing value where TRUE/FALSE needed in DiveRsity

It would be easier to find the problems by providing some data as a reprex.

In particular, what package are you using? Is it diveRsity? You should also make sure the code you provide does create that error message on a fresh R session, in your example you read X but then execute basicStats on x, R is case-sensitive so X and x are different variables.