Using packages that are not imported as part of examples in a vignette

I am using functions from the forcats and devtools packages in a vignette for a package I am developing. I have them listed in the Suggests (not not Imports) field in the NAMESPACE file.

When I run devtools::check(), the following NOTE is returned:

checking for unstated dependencies in vignettes ... NOTE
'::' or ':::' imports not declared from:
  ‘devtools’ ‘forcats’

According to the answer to this question on Stack Overflow, adding these to the Suggests field ought to resolve the issue causing the note, but this doesn't seem to do so for me in this case. Can you recommend how you would address this note? If it is helpful, a link to the package is here.


I'd try using also the suggestions reported in the second answer.

  1. Add % \VignetteDepends{forcats} in the header of the vignette.

  2. Enclose the line d <- forcats::gss_cat within a if (require(forcats) {} construct.


Thank you! Just to confirm, the require construct includes a closing bracket after (forcats), i.e.:

if (require(forcats)) {
    d <- forcats::gss_cat

Yes. I'd also say that you should keep anything that could need d within the braces, so that building / recreating the vignette does not fail if forcats is not available.

1 Like

I'd also suggest using requireNamespace() and not require() e.g. dependencies in R Packages).

require() will attach a package, requireNamespace() just loads it (subtle differences that Hadley writes about in the same book here).


I think your problem is likely that you have two entirely separate Suggests sections in your DESCRIPTION.

ugh, that's embarassing! fixed this