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.