title: R namespace access and match.fun
body: <p>I'm working on an R package where one of the functions contains a <code>match.fun</code> call to a function in a package that's imported to the package namespace. But on loading the package, the <code>match.fun</code> call can't find the function name. From <a href="https://github.com/hadley/devtools/wiki/Namespaces" rel="nofollow">Hadley Wickham's description</a> I think I'm doing everything right, but this is clearly not the case. </p>
  
  <p>Example:</p>
  
  <pre><code># in the package file header, for creation of the NAMESPACE via roxygen2:
  ##` @import topicmodels
  
  # The function declaration in the package
  ModelTopics &lt;- function(doc.term.mat, num.topics, topic.method="LDA"){
    topic.fun &lt;- match.fun(topic.method)
    output &lt;- topic.fun(doc.term.mat, k=num.topics)
    return(output)
  
  }    
  </code></pre>
  
  <p>And then in R:</p>
  
  <pre><code>&gt; library(mypackage)
  &gt; sample.output &lt;- ModelTopics(my.dtm, topic.method="LDA", num.topics=5)
  Error in get(as.character(FUN), mode = "function", envir = envir) : 
    object 'LDA' of mode 'function' was not found
  </code></pre>
  
  <p>From my understanding of namespaces, the <code>match.fun</code> call should have access to the package namespace, which should include the <code>topicmodels</code> functions. But that doesn't appear to be the case here. If I import <code>topicmodels</code> directly to the global namespace for the R session, then this works. </p>
  
  <p>Any help is much appreciated. This is R64 2.14.1 running on OSX. </p>
  
  <p>UPDATE:
  The package is <a href="https://github.com/markhuberty/leghist" rel="nofollow">here</a></p>
  
  <p>Re the DESCRIPTION file, perhaps that's the problem: roxygen2 doesn't update the DESCRIPTION file with <code>Imports:</code> statements. But none of the other packages are listed there, either; only the <code>match.fun</code> calls appear to be affected. </p>
  
  <p>Re the NAMESPACE extract, here's the import section:</p>
  
  <pre><code>import(catspec)
  import(foreach)
  import(gdata)
  import(Hmisc)
  import(igraph)
  import(lsa)
  import(Matrix)
  import(plyr)
  import(RecordLinkage)
  import(reshape)
  import(RWeka)
  import(stringr)
  import(tm)
  import(topicmodels)
  </code></pre>