title: Define groups of functions
body: <p>I'm working on building an R package, and I've encountered a structural problem that I'm not sure how I should solve.  I have several different distributions that I'd like to implement in my package (normal, student's t, etc.) and for each distribution I'll have several functions related to it.  I will then have an additional function that uses these functions to execute some process, and so I'm trying to avoid having to define all of these functions with different names.</p>
  
  <p>To be more clear, let me give a simple example.  Let's say I want to write a simple package to do maximum likelihood estimation for several distributions.  Ideally, I'd like to call an <code>MLE</code> function like:</p>
  
  <pre><code>MLE(data, distribution = "normal")
  </code></pre>
  
  <p>and then have the MLE function load all the related normal distribution functions that it needs.  So, it may load <code>density</code> and <code>gradDensity</code> specific to the normal distribution and operate with these functions.  However, if I call</p>
  
  <pre><code>MLE(data, distribution = "studentT")
  </code></pre>
  
  <p>then <code>density</code> and <code>gradDensity</code> are defined as different functions, now specific to the Student's t distribution.</p>
  
  <p>My question is this: how can I appropriately define the <code>density</code> and <code>gradDensity</code> functions for each different distribution I'm interested in and load them when I need them?  I've considered defining a new class for this package and having this object contain all the distribution functions I'd need, but this seems problematic because I want one of the functions in this object to be able to call another one of the functions in the object (for example, <code>gradDensity</code> may call <code>density</code>).  I also considered defining separate environments for each distribution, but I wasn't sure if that was good practice.  Ideally, I'd also like users to be able to define their own distribution and then use this package as well, but I'm having a hard time understanding how to appropriately construct this structure in R.</p>