执行 devtools::check(cran=TRUE) 后 我收到这个警告。 我看到其他人说我们不能在 CRAN 上使用“:::”。 那么,如何解决这个问题呢?谢谢您的帮助!
> checking dependencies in R code ... NOTE
Unexported object imported by a ':::' call: 'tsfeatures:::scalets'
See the note in ?`:::` about the use of this operator.
在这里你可以找到答案。 https://github.com/drsimonj/twidlr/issues/16
总结一下有很多选择:
fun <- utils::getFromNamespace("fun", "pkg")
。当您构建包时,函数的顺序和位置并不相关(除非您使用 S4 或其他外来对象)。我刚刚遇到了类似的情况,我想使用
cli
包中的非导出函数(请参阅下面的简化示例代码)。我所做的是将函数环境更改为 cli
命名空间。因此,我的函数可以直接访问 cli
内部结构。代码通过了R CMD CHECK
。
注意:当然,只有当您的函数与其他包强耦合时,这种方法才有意义,这里
cli
。
# code adapted from cli_line but without linebreak
cli_cat <- function(..., col = NULL, background_col = NULL, file = stdout()) {
out <- paste0(..., collapse = "\n")
out <- apply_style(out, col)
out <- apply_style(out, background_col, bg = TRUE)
cat(out, sep = "", file = file, append = TRUE)
}
environment(cli_cat) <- asNamespace("cli") # to access internal cli functions
cli_cat("hello", col="grey")