I like putting different functionality in their own files.
But I don't like R's package system. It's rather hard to use.
I prefer a lightweight alternative, to place a file's functions inside an environment (what every other language calls a "namespace") and attach it. For example, I made a 'util' group of functions like so:
util = new.env()
util$bgrep = function [...]
util$timeit = function [...]
while("util" %in% search())
detach("util")
attach(util)
This is all in a file util.R. When you source it, you get the environment 'util' so you can call
util$bgrep()
and such; but furthermore, the
attach()
call makes it so just
bgrep()
and such work directly. If you didn't put all those functions in their own environment, they'd pollute the interpreter's top-level namespace (the one that
ls()
shows).