gaynorr / AlphaSimR

R package for breeding program simulations
https://gaynorr.github.io/AlphaSimR/
Other
43 stars 18 forks source link

Reduce nInd argument value on the fly if there is less individuals than requested #30

Closed gregorgorjanc closed 2 years ago

gregorgorjanc commented 2 years ago

Consider this example:

# AlphaSimR
founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 10)
SP <- SimParam$new(founderGenomes)
basePop <- newPop(founderGenomes)
selectInd(pop = colony1@virgin_queens , nInd = 4)
# Error in selectInd(pop = slot(x, caste), nInd = nInd, use = "rand") : 
#  Not enough suitable candidates, check request value and sex 

While the error makes total sense, I think it would be beneficial if the selectInd() function would throw a warning instead of an error (so the user would be warning something is amiss) and return all individuals in the population.

This error came up many times in our simulations with insects where the number of individuals can vary hugely and most often we then just take what we have.

Happy to provide a pull request if this change would be considered.

gaynorr commented 2 years ago

I've changed the behavior as suggested. The selectWithinFam function already had this behavior, so it makes everything a bit more consistent. I may add a toggle on this behavior in the future to let the user specify whether it should be an error or a warning.