I'm working on an R package where one of the functions contains a match.fun call to a function in a package that's imported to the package namespace. But on loading the package, the match.fun call can't find the function name. From Hadley Wickham's description I think I'm doing everything right, but this is clearly not the case.

From my understanding of namespaces, the match.fun call should have access to the package namespace, which should include the topicmodels functions. But that doesn't appear to be the case here. If I import topicmodels directly to the global namespace for the R session, then this works.

Re the DESCRIPTION file, perhaps that's the problem: roxygen2 doesn't update the DESCRIPTION file with Imports: statements. But none of the other packages are listed there, either; only the match.fun calls appear to be affected.

+1 Nice question. Is your package on github or somewhere we can see the code?
–
AndrieAug 16 '12 at 15:36

Can you please also add 1) the extract from the NAMESPACE file that shows that topicmodels gets imported, and 2) the extract from DESCRIPTION that shows Imports: topicmodels?
–
AndrieAug 16 '12 at 15:39

Option 2: Export the functions from topicmodels that you need

If you make the necessary functions from topicmodels available in your NAMESPACE, your code should also work.

Do this by either:

Selective exporting LDA and other functions to the namespace using @export

Declare a dependency, using Depends: topicmodels - this is the same as calling library(topicmodels) in the global environment. This will work, but is possibly a bit of a brute force approach. It also means that any subsequent library call can mask your LDA function, thus leading to unexpected results.

Answering my own question: the DESCRIPTION file wasn't updating the Imports: and Depends: fields after re-roxygenizing the updated code. Hence the match.fun issues. Out of curiousity, why does this affect match.fun but not a range of other function calls made elsewhere to imported package functions?