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.


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.


  1. Functions

  2. Packages

  3. Global.R in shiny apps

    There are sometimes benefits using this method rather than packages, this is easier to maintain.

  4. Source file

  5. Vectorization


  1. Querying database that are highly structured with a single keyword/index - functions.

  2. Describing variables with a table that looks like a certain way - code snippets.

  3. 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.

More Readings

Abstract Coding In R