3

When running R CMD check I am getting

> checking examples ... ERROR
...
...
  > lfqplotter$pca()
  Error in inner_join(wide$annotation, xx) : 
    could not find function "inner_join"
  Calls: <Anonymous> -> <Anonymous>
  Execution halted

A similar question was asked before. "Could not find function" in Roxygen examples during CMD check

But in my case it is a function from an imported package (dplyr), which I did list under Imports in the DESCRIPTION file.

Imports:
dplyr

I know that I could specify and @importFrom clause with roxygen2. However because the package contains dozens of functions with examples, and many use dplyr::inner_join and other dplyr functions, I would prefer not have to fill the comments with hundreds of @importFrom dplyr inner_join select etc etc, or be adding @import dplyr everywhere. Alternatively, I could, but I do not want to prefix every dplyr function call with dplyr::. Is there any other option to get examples working and imported package functions visible?

Answer

Based on the Answer by @Roland and @Waldi I added an R file AAA_importFrom.R to the project with a block of:

#' @importFrom tidyr ...
#' @importFrom dplyr ...
...
#'
NULL

and removed all the @importFrom clauses from the function documentations.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
witek
  • 984
  • 1
  • 8
  • 25
  • 1
    It's not sufficient to have a package under `Imports` in the DESCRIPTION file (study *Writing R Extensions*). You must additional import specific (or all) functions in your NAMESPACE file. An alternative option would be to list the package under `Depends` in your DESCRIPTION file. But that's not recommended practice (in particular for `dplyr`which is not shy with masking base functions). – Roland Jun 17 '20 at 07:11
  • @Roland Since I am using roxygen2 I am not editing NAMESPACE by hand. What other option of adding the imports to the namespace do I have? – witek Jun 17 '20 at 07:12
  • Well, the options are `@import` or `@importFrom` directives in roxygen2. Unfortunately, you say you are unhappy with these. So, you don't want roxygen2 to manage your NAMESPACE file but you also don't want to manage it manually. I'm not sure what kind of advice you are looking for if you already exclude all sensible options. – Roland Jun 17 '20 at 07:25

1 Answers1

0

You should also have :

importFrom(dplyr,inner_join)

in NAMESPACE

you can get Roxygen to create this in NAMESPACE by having :

#' @ImportFrom dplyr inner_join
NULL

in one of your package's R scripts

Waldi
  • 39,242
  • 6
  • 30
  • 78