[Rd] Best practices for writing R functions
Davor Cubranic
cubranic at stat.ubc.ca
Wed Jul 27 00:19:00 CEST 2011
On 2011-07-23, at 5:57 AM, Alireza Mahani wrote:
> Another trick to reduce verbosity of code (and focus on algorithm logic
> rather than boilerplate code) is to maintain a global copy of variables (in
> the global environment) which makes them visible to all functions (where
> appropriate, of course). Once the development and testing is finished, one
> can tidy things up and modify the function prototypes, add lines for
> unpacking lists inside functions, etc.
I think you'd be better off to stay away from such tricks. It's asking for trouble later on, because unless you have really good unit tests it is very easy to miss a variable during "tidying up" and end up with code that works fine in your development environment but is full of bugs once you distribute it to others.
Davor
More information about the R-devel
mailing list