4

I had my R-package using RDCOMClient via DESCRIPTION file:

Suggests: RDCOMClient

and the following (perfectly working) code:

GetNewWrd <- function() {

  stopifnot(require(RDCOMClient))

  # Starts the Word application with wrd as handle
  wrd <- RDCOMClient::COMCreate("Word.Application", existing=FALSE)
  newdoc <- wrd[["Documents"]]$Add("",FALSE, 0)
  wrd[["Visible"]] <- TRUE 

  invisible(wrd)
}

Nowadays this seems to be considered as bad practice and "Writing R Extensions, 1.1.3.1 Suggested packages" tells us to formulate:

if (requireNamespace("rgl", quietly = TRUE)) {
   rgl::plot3d(...)
} else {
   ## do something else not involving rgl.
}

or: .. If the intention is to give an error if the suggested package is not available, simply use e.g. rgl::plot3d.

Recoding this (to my understanding) would mean, just to delete the require-statement:

GetNewWrd <- function() {

  # Starts the Word application with wrd as handle
  wrd <- RDCOMClient::COMCreate("Word.Application", existing=FALSE)
  newdoc <- wrd[["Documents"]]$Add("",FALSE, 0)
  wrd[["Visible"]] <- TRUE 

  invisible(wrd)
}

Doing this leads to the following runtime error:

Error in RDCOMClient::COMCreate("Word.Application", existing = FALSE) :
  could not find function "createCOMReference"

createCOMReference is a function in RDCOMClient, which apparently can't be found without the explicit require statement.

How for God's sake am I supposed to integrate RDCOMClient in my package complying to CRAN's policies???

Andri Signorell
  • 1,112
  • 10
  • 22
  • `createCOMReference` might not be exported from RDCOMClient. Have you looked at other accepted packages such as `DescTools`? Furthermore, now that I read section 1.1.3.1 again I don't think it is saying you cannot use `require`, but rather that in those cases where it is optional, that the `requireNamespace` route might create fewer problems. It is concerned that about a chance that functions could be over-written. That seems unlikely for RDCOMClient functions. – IRTFM Jan 12 '15 at 22:53
  • I am the author of DescTools and I wanted to upload an update. But Prof. Ripley refused with the comment: You did not comply with the policies re Suggests or Enhances not in mainstream repositories: RDCOMClient * checking dependencies in R code ... NOTE 'library' or 'require' call to ‘RDCOMClient’ in package code. Please use :: or requireNamespace() instead. See section 'Suggested packages' in the 'Writing R Extensions' manual. – Andri Signorell Jan 12 '15 at 23:32
  • Color me puzzled. I would have thought that OmegaHat would be considered a mainstream repo. Would there be any value in contacting Duncan Temple Lang? – IRTFM Jan 12 '15 at 23:36
  • :-) It's even stranger as the most current version can be found on his own Website: http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.0/. Maybe a good idea to contact Duncan Temple Lang directly.... – Andri Signorell Jan 13 '15 at 00:01

1 Answers1

0

Very old question, but I stumbled upon the same issue. I use the following workaround which does not issue a warning in R CMD check but seems to me like an awful hack:

if (requireNamespace("RDCOMClient", quietly = TRUE)) {
   if (!"RDCOMClient" %in% .packages()) {
      attachNamespace("RDCOMClient")
   }
# ...
}
thothal
  • 11,321
  • 1
  • 23
  • 56