Home > database >  How to use a function from an external package in the example part of an R file
How to use a function from an external package in the example part of an R file

Time:08-19

I am working on an R package and in the @examples part of my R file I call on ggplot from the ggplot2 package in my example code. I am not using any part of ggplot2 in my actual package code and so I wasn't sure how to call the ggplot2 functions.

Originally I thought I would just need to use ggplot2::ggplot() but the R CMD Check complained. So I added it to the Imports list in the DESCRIPTION file but then R complained that it shouldn't be in there since I am not using it in my code functions. I then thought to add it to using @import ggplot2 ggplot in my .R file but it seemed to complain about that as well.

Can anyone tell me how I should reference external functions in only the example part of my .R file? I tried reading through the R help pages on CRAN as well as Googling for an answer but I guess I wasn't able to find what I needed.

CodePudding user response:

Packages used for examples only should be listed in 'Suggests:' instead of 'Imports:' in the DESCRIPTION file

  • Related