Abstraction in R
Why taking time to do abstractions will boost your productivity with R?
Improve scalability
Abstraction vastly improve scalability by distilling one solution to a problem to many other similar problems, thus reducing repetitive work, and often do not require much more work.
Less is more
When it comes to typing, less is more. When you have to type a chunk of code over and over to do some routine task, do youself a favor and make it into functions if you are doing idential task and only changing variable values, if it’s too much of work or if it invovle too many variables, at least make it into code snippets that you can easily call back by typing a few keywords.
Better understanding of the problem.
Understand one problem by thinking about 100 instead. This does not work all the time tho.
Reproducibility
Share functions within the team as standards can vastly improve reproducibility. For example, debugging will take less time as you already know what functions your team is using and you can just get to the bottom of it instead of spending time deciphering the 100 ways of doing the same thing in R.
How
Functions
Packages
Global.R in shiny apps
There are sometimes benefits using this method rather than packages, this is easier to maintain.
Source file
Vectorization
Scenarios
Querying database that are highly structured with a single keyword/index - functions.
Describing variables with a table that looks like a certain way - code snippets.
Clinical Trials Protocols - Lots of them.
This is perfect example to automate. Studies designs may differ, but database and data dictionary are widely shared across studies.