The recommendation used (in 2013 when I first wrote this answer) to be to require
in a conditional statement. Now in 2016 the official recommendation is to use ::
and let R print the there is no package called X
error:
##' Visualization
##'
##' @description Visualize the data. \pkg{\link{lattice}} package required.
##' @param x Data.
##' @param y More data.
##' @seealso \pkg{\link{lattice}}
##' @export
vizz <- function(x, y){
lattice::xyplot(y ~ x)
}
And only keep Suggests: lattice
in your DESCRIPTION
(no import
in the NAMESPACE
).
If you want to customize the error message you can now use requireNamespace(lattice)
in a conditional statement, such as:
vizz <- function(x, y){
if (! requireNamespace("lattice", quietly = TRUE)) {
stop("Please install lattice: install.packages('lattice')")
lattice::xyplot(y ~ x)
}