首页 > 解决方案 > 在包检查中运行示例时“找不到函数”

问题描述

跑步R CMD check时我得到

> checking examples ... ERROR
...
...
  > lfqplotter$pca()
  Error in inner_join(wide$annotation, xx) : 
    could not find function "inner_join"
  Calls: <Anonymous> -> <Anonymous>
  Execution halted

之前有人问过类似的问题。 CMD 检查期间 Roxygen 示例中的“找不到函数”

但在我的情况下,它是一个来自导入包 (dplyr) 的函数,我在DESCRIPTION 文件中的Imports 下列出了它。

Imports:
dplyr

我知道我可以@importFromroxygen2. 但是,由于该包包含数十个带有示例的功能,以及许多使用dplyr::inner_join和其他dplyr功能,我宁愿不必在评论中填写数百个@importFrom dplyr inner_join select etc etc,或者@import dplyr到处添加。或者,我可以,但我不想在每个 dplyr 函数调用前加上dplyr::. 是否有任何其他选项可以使示例工作和导入的包功能可见?

回答

根据@Roland 和@Waldi 的回答,我AAA_importFrom.R在项目中添加了一个 R 文件,其中包含以下内容:

#' @importFrom tidyr ...
#' @importFrom dplyr ...
...
#'
NULL

并从函数文档中删除了所有 @importFrom 子句。

标签: rdplyr

解决方案


你还应该有:

importFrom(dplyr,inner_join)

在命名空间中

您可以通过以下方式让 Roxygen 在 NAMESPACE 中创建它:

#' @ImportFrom dplyr inner_join
NULL

在你的包的一个 R 脚本中


推荐阅读