gaynorr / AlphaSimR

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

Add bound-checks (negative values) on arguments such as nInd or document the behaviour of such cases? #26

Closed gregorgorjanc closed 2 years ago

gregorgorjanc commented 2 years ago

Consider the below example reported by Irene Breider, where calling selectInd(..., nInd = -4) removes 4 individuals, which makes sense looking at the selectInd() code (return(pop[take[0:nInd]])), but this can lead to unintended "bugs" in user scripts.

Options: 1) Add bound-checks (negative values) for arguments such as nInd 2) Document behaviour with negative values

@gaynorr what do you suggest?

founderPop = quickHaplo(50, 1, 100)
SP = SimParam$
  new(founderPop)$
  addTraitA(100)$
  setVarE(h2=0.3)$
  setTrackRec(TRUE)
pop = newPop(founderPop)
NewPop=selectInd(pop,-4)
#NewPop gives:
#An object of class "Pop" 
#Ploidy: 2 
#Individuals: 46 
#Chromosomes: 1 
#Loci: 100 
#Traits: 1 
gaynorr commented 2 years ago

Done