@importFrom utils head causing strange issues

When I did a CRAN check I got an issue pop up:

Error: package or namespace load failed for ‘bestpackage’:
    object 'head' not found whilst loading namespace 'bestpackage'
   Execution halted
   
   It looks like this package (or one of its dependent packages) has an
   unstated dependence on a standard package.  All dependencies must be
   declared in DESCRIPTION.
   See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
   manual.

Fair enough, I already had utils in my imports in the DESCRIPTION file, but popped in a nice @importFrom utils head into the function docs I created that was using head.

The next CRAN check now did not have that error, but now my tests are not passing that have head in them. The error being:

 Error in UseMethod("head") : 
  no applicable method for 'head' applied to an object of class "data.frame"

Any idea why adding in the @importFrom would be causing that?

EDIT:

I think this is is because my test was running head in another packages' namespace (SparkR) that does not have utils in its imports or depends. SparkR will automatically scour the function being run and pull in from your search path any namespaces that are missing in the function you submitted. So my question really is:

When I use @importFrom utils head, it creates an entry in my Namespace. What does this actually do with regard to the search path for the S3 generic? It seems like SparkR accessed the right S3 method before, but after I add the @importFrom it is not loading the needed S3 method.

Dan

It may be worth noting that the function I added the @importFrom to was creating a method for the utils::head S3 generic.

Hi @dzafar, I'd like to help you troubleshoot this issue. Would you be able to provide a link to your package? If not, would you be able to create a minimal example package that recreates the error?

1 Like

Thanks for the offer to help here, but looks like it was something specific to the packages I was using. Have solved it. Thanks though!

2 Likes

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Hello, there was no solution here. Not sure how to delete the post.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.