6

I am working on my R package. I am getting this error:

Namespaces in Imports field not imported from:
   ‘kableExtra’ ‘ranger’
  All declared Imports should be used.

I get this error with devtools::check_rhub() i.e. on linux and windows platform. When I check my package locally (mac os) with devtools::check() all checks gets passed successfully.

I looked deeper into the imports of my description file, currently I am doing:

Imports:  
    ranger(>= 0.10.1),
    Metrics(>= 0.1.3),
    kableExtra(>= 0.9.0)

I am using functions from ranger and kableExtra using :: like ranger::function_name, kableExtra::function_name since there are just one or two functions I need.

I am not doing importFrom in Namespace file. Because, like I said, there are just 1 or 2 functions I need to borrow.

Why am I getting this error ? What am I missing ?

YOLO
  • 20,181
  • 5
  • 20
  • 40
  • @Suren is incorrect, you do need `Imports: ranger` in the `DESCRIPTION` file even with the `::` notation. The problem is that the check code sometimes misses uses of `::`, so some of the notes are spurious. – user2554330 Feb 07 '23 at 17:56

2 Answers2

5

I fixed the problem with this workaround:

  1. Add the name of the package in Namespace file with importFrom.
  2. Doesn't matter if you are borrowing just one function from a package using ::, if the package name is mentioned in the Imports or Depends, it will raise an error.
YOLO
  • 20,181
  • 5
  • 20
  • 40
  • 1
    For people using Roxygen, just add `@importFrom ` somewhere in the package. That way during the documentation step it's added to the NAMESPACE file (and won't show up in the actual documentation of the function). See for example the setup step in the vignette of Rdpack: https://cran.r-project.org/web/packages/Rdpack/index.html – Felix Jassler Mar 12 '22 at 19:29
  • The problem with that solution is that it causes the imported package to be loaded when the using package was loaded. Using `pkg::fn` notation delays the load until it is needed. – user2554330 Feb 07 '23 at 17:54
0

When the error is related to the package Rdpack

Namespace in Imports field not imported from: 'Rdpack'

it is more subtle as we do not use directly this package (it is used internally during devtools::check(). The Rdpack documentation indicates that this line:

# ' @importFrom Rdpack reprompt

must be added anywhere in your documentation (if you are using roxygen2) or this line in NAMESPACE

importFrom(Rdpack,reprompt)

if you maintain NAMESPACE manually

Denis Cousineau
  • 311
  • 4
  • 16