Split your work
Working with a monolithic 2000-line script can be overwhelming and inefficient 😱.
This lesson delves into the drawbacks of such an approach and offers practical strategies for dividing your work into manageable, coherent segments.
Too long is too long
I am sure it already happened to you.
You write some code to analyse a dataset. It triggers some new questions. So you add some more code to understand. And so on!
You end up with a 2000 lines long file that takes 35 minutes to run from start to end.
This is annoying!
❌ Slow: when you open R again to modify the end of your script, you have to run the beginning again!
❌ Hard to maintain: navigating a 2000 lines long file is not fun at all.
❌ Bad for collaboration: if you are several people working on the same massive file, it is very likely that you get conflicts.
So. How can you do?
➡️ You have to modularize your code.
Modular programming is a design technique that involves separating a program into distinct modules that can be developed, tested, and debugged independently of each other.
And there are 3 main ways to do so:
1️⃣ Use Functions. Source()
them.
In the previous lesson we saw how to avoid duplication in code by using functions.
This lesson is not ready yet! 🙃
Become a member now: you'll be the first accessing it, at a very preferential price.
Or Login