R: cannot find exported function even after importing entire namespace

Tag: r , package Author: coeel Date: 2014-01-23

I'm building a package, myPackage that imports from several other packages. The problem is that a function fun (it's actually a method) that is exported from another package otherPackage cannot be found when run. I did all of the following:

  1. Imports: otherPackage and Depends: methods in myPackage's DESCRIPTION file
  2. import(otherPackage) in myPackage's NAMESPACE file
  3. Also tried adding importMethodsFrom(otherPackage,"fun")

The only way I found it to work is if I replace Imports: otherPackage with Depends: otherPackage, but we all know that it is recommended to import another package's namespace instead of attaching it to the search path. Can someone please explain why Importing it doesn't work?

Specifics: the function in question is keys from package AnnotationDbi in Bioconductor. The specific error is Error in .select(x, keys, columns, keytype) : could not find function "keys"

Thank you.

You need Imports: AnnotationDbi in your description, and importMethodsFrom(AnnotationDbi, keys) in your namespace.
Tried that, no luck. See points 1 and 3 in my edited post.
It looks like AnnotationDbi actually has several packages listed as depends (including methods). This might make it so that the only option you have is to use depends yourself.
I tried to import every package in the depends of AnnotationDbi with no luck either. I'm really confused about why importing all of those namespaces doesn't work.
@FBC it's not clear what you tried at the same time. I'd recommend creating a minimal reproducible example that illustrates the problem, and post publicly (ideally on github)