20

I've been poking through a bunch of different packages and I'm noticing that there really isn't a clear and concise method for function storage. Some package authors pack all of them in one file while other authors split them into individual files.

I've read a number of package creation guides but none of them provide specific guidelines or suggestions.

Would love to hear your thoughts on this.

Marek
  • 49,472
  • 15
  • 99
  • 121
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255

2 Answers2

16

The best reference I have found on the topic thus far is from Hadley Wickham's R book draft. Quoting from there:

It's up to you how you arrange your functions into files, but I suggest grouping related functions into a single file. My rule of thumb is that if I can't remember which file a function lives in, I probably need to split them up into more files - having one function per file is perfectly reasonable, particularly if the functions are large or have a lot of documentation.

diliop
  • 9,241
  • 5
  • 28
  • 23
8

I use one function per file. It helps me in the developing stage because I can source individual file (CTRL+R+S in Eclipse) and have a changed function handy. I also prefer changing tabs than scrolling up and down a single file. But at the end of the day it probably depends on what you're used to and what tools you use for development.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • 1
    Same for me and for the same reason. Only functions I keep in one file are `plot.` `print.` and so. Tbh, is there any reason why you wouldn't store functions in separate files? – Sacha Epskamp May 28 '11 at 09:19
  • 1
    @SachaEpskamp If I have many small functions, I collate them in one file. Sorry for a bit late answer. :) – Roman Luštrik Mar 03 '14 at 12:40