我通过描述文件使用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)
}如今,这似乎被认为是不好的做法,“编写R扩展,1.1.3.1建议的软件包”告诉我们要制定:
if (requireNamespace("rgl", quietly = TRUE)) {
rgl::plot3d(...)
} else {
## do something else not involving rgl.
}或者:.。如果意图是在建议的包不可用时出错,只需使用例如rgl::plot3d。
重新编码(据我理解)意味着,只需删除require语句:
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语句是找不到的。
看在上帝的份上,我怎么能按照CRAN的政策把RDCOMClient集成到我的包里呢?
发布于 2021-01-20 10:46:12
很老的问题,但我偶然发现了同样的问题。我使用以下解决方法,它不会在R CMD check中发出警告,但在我看来似乎是一个可怕的攻击:
if (requireNamespace("RDCOMClient", quietly = TRUE)) {
if (!"RDCOMClient" %in% .packages()) {
attachNamespace("RDCOMClient")
}
# ...
}发布于 2022-07-01 16:10:14
要想找到解决此问题的潜在解决方案,请查看https://github.com/AndriSignorell/DescToolsAddIns/issues/1#issuecomment-1172495715和(原始解决方案在) https://github.com/omegahat/RDCOMClient/issues/32#issuecomment-882969642,只要原始回购上的PR尚未完成,您可以尝试使用devtools::install_github("BSchamberger/RDCOMClient")作为RDCOMClient github回购的分支,包括最近对R4版本的一些错误处理和修改的“修复”。
此外,我还做了“丑陋”(在通常不鼓励的方法意义上)的事情,并把RDCOMClient放在Depends: (而不是Imports:)的DESCRIPTION文件中,这至少在我的例子中(在依赖的包中有相同的错误)解决了could not find createCOMReference问题。
https://stackoverflow.com/questions/27910886
复制相似问题