[R-pkg-devel] Suggests in a Package

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Tue Feb 4 19:20:15 CET 2020


On 04/02/2020 1:13 p.m., Roy Mendelssohn - NOAA Federal via 
R-package-devel wrote:
> Hi All:
> 
> I still get a little confused on what it means if a package is listed in "Suggest" in my package.  I have been working to try and keep dependencies down.  One of my packages produces maps with data, and I have been asked if the maps can be made interactive.  It turns out this can be done very easily using "plotly" and I want to include something about that in the vignette. What my question is if I Suggest "plotly" in the package,  does a user have to have "plotly" installed in order to install and run the package?  My understanding is not,  so someone who doesn't want to do this doesn't need to install "plotly" but I wanted to double-check.

Your understanding is correct:  someone who doesn't have plotly 
installed should still be able to install and run your package.

You should make sure that any functions that need plotly check for it 
first.  The recommended way to do that is to use a 
requireNamespace("plotly") test, e.g. something like

   if (requireNamespace("plotly")) {
      plotly::plotly(...)
   } else
      stop("This function requires the 'plotly' package")

Your tests that use such a function should only be run if 
requireNamespace("plotly") returns TRUE.

Duncan Murdoch



More information about the R-package-devel mailing list