Pulling out the major parts of your scripts as separate functions has the advantage that you can more easily reuse that code.

But functions sitting deep within some project directory are not likely to be used again. (“It’s in a file called func.R, but which project was I working on?”)

When possible, package up those useful functions as a stand-alone thing. This will make it easier for you (and others) to reuse them. It’s also a good opportunity to document those functions.

Writing R packages is really not so hard as one might think. See my R package primer, Hadley Wickham’s R packages book, or Hilary Parker’s tutorial on R packages. If you’ve written a personal R package, you might include your miscellaneous functions there, or write a separate small package specific to your project.

If you prefer python to R, this may be even easier for you: a python module is not much more than a file with a bunch of function definitions. Just add some docstrings.


Now go to the page about version control.