Open PhDyellow opened 5 years ago
The programming section (and the Github and Rstudio sections) are direct copies from the OHI book. I intend to go back and adapt them more thoroughly for our purposes.
Your title suggests you are advocating to not teach for loops? I agree with your sentiments re it not being useful for parallel processing, but for new programmers I think the for loop is conceptually much easier to grasp.
I would advocate for keeping the Studio and programming sections for beginners (so maybe I need to remove some irrelevant content) and those who may have come from other languages where for loops are directly analogous (such as myself who came from a MATLAB background only 12 months ago).
But I think we should include a new chapter in the book about moving to parallel processing. Some basic tips, a list of functions to substitute, packages to investigate etc.
I'll add it as a TODO. I wanted to get some bare bones together, and then at a future lab meeting I'm going to call for volunteers to modify chapters to suit our needs.
@jaseeverett, I notice in the programming section, we teach people to use
for
loops. For parallel processing, it is much better to be usinglapply
.We could also use
foreach
.Moving from a
for
loop tolapply
orforeach
is a major refactor, because thefor
loop expects variables outside the loop to be initialised, and expects to be modifying those variables during the loop.lapply
andforeach
create a new scope inside, so that generally you use them as functions that take inputs and return lists.Moving from
lapply
toparLapply
orfuture_lapply
is only a minor refactor, with an extra line of code at the start of the script to specify the parallel model.