Skip to content
Prev 11082 / 12125 Next

[R-pkg-devel] conditional import of a package?

Thanks, Duncan, for the kind advice. 

In my understanding, this is what I have done (or I tried to do).  My code is as follows:

  opt.methods <- c("Nelder-Mead", "BFGS", "nlminb")
  if(requireNamespace("nloptr", quietly = TRUE)) {
    nloptr.methods <- c("newuoa", "bobyqa", "cobyla")
    if(opt.method %in%  nloptr.methods) require(nloptr, quietly=TRUE)
    opt.methods <- c(opt.methods, nloptr.methods)
   }

<skip>

   if(opt.method %in% nloptr.methods) {    
      pos <- match("package:nloptr", search())
      nloptr.method <-  get(paste("nloptr", opt.method, sep="::"), pos=pos)
      opt <- nloptr.method(<args>)
      }
       
In the DESCRIPTION file there is
   Suggests: ggplot2, survival, nloptr

However, when I run ?R CMD check <etc>?, I get the following message 
* checking package dependencies ... ERROR
Namespace dependency missing from DESCRIPTION Imports/Depends entries: ?nloptr?

See section ?The DESCRIPTION file? in the ?Writing R Extensions?
manual.
* DONE

And - admittedly - I have no idea about how to insert appropriate import statements in NAMESPACE.


Best regards,

Adelchi