Command-line scripts
In the previous chapter, you generalized an R script for simulating genetic drift into a dedicated function. In this way, you have taken an important step towards reproducibility of your code. In situations in which you need to run a number of simulations for a (potentially very large) set of parameter combinations, a naive approach would’ve been to copy-paste bits of code, one copy for one batch of simulations. This would work, but it would be very annoying and boring to do, and it would be significantly error-prone.
Finding a mistake in a very long R script which contains repeated copies of very similar bits of code is a disaster. Instead of this repetition, you can now have all the logic of your simulation in one single place (a function) and reduce the repetition to only calling the function with specific parameter values as needed. In fact, you later went even one step further, and reduced even that repetition to calling a single for
loop!