我通过DESCRIPTION文件使用RDCOMClient获得了我的R包:
建议:RDCOMClient
以及以下(完美工作)代码:
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)
}
如今,这似乎被认为是不好的做法,“Writing R Extensions, 1.1.3.1 Suggested packages”告诉我们制定:
if (requireNamespace("rgl", quietly = TRUE)) {
rgl::plot3d(...)
} else {
## do something else not involving rgl.
}
或: ..如果在建议的包不可用时打算给出错误,只需使用例如 rgl::plot3d。
重新编码(据我所知)意味着,只是删除要求语句:
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)
}
这样做会导致以下运行时错误:
Error in RDCOMClient::COMCreate("Word.Application", existing = FALSE) :
could not find function "createCOMReference"
createCOMReference 是 RDCOMClient 中的一个函数,如果没有明确的 require 语句,显然无法找到它。
看在上帝的份上,我应该如何将 RDCOMClient 集成到我的包中以符合 CRAN 的政策???