phenClones() errors during the permutation loop because it passes a vector to the size argument of sample():
ts <- sample(pvt$predicted.value, dim(mgd) * 2, replace = FALSE)
dim(mgd) returns a vector (c(n_pairs, 2)), so dim(mgd) * 2 is also a vector, which leads to:
"Error in sample.int(...): invalid 'size' argument".
Probably need to change it nrow(mgd) instead