【问题标题】:"Could not find function" in Roxygen examples during CMD checkCMD 检查期间 Roxygen 示例中的“找不到函数”
【发布时间】:2017-11-27 02:02:03
【问题描述】:

我正在 RStudio 中对一个包运行 CMD 检查,其中一部分分析了内联 Roxygen 文档中的 @examples

我收到此错误:

checking examples ... ERROR
Running examples in ‘packagename-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: checkDate
> ### Title: Ensure that a date string is a valid date
> ### Aliases: checkDate
> 
> ### ** Examples
> 
> checkDate("2017-05-06")
Error: could not find function "checkDate"

在我的 .R 文件中,文档定义为:

#' Ensure that a date string is a valid date
#'
#' @param dateString A string (eg. "2017-12-04").
#' @return TRUE or FALSE (and a warning if FALSE).
#' @examples
#' checkDate("2017-05-06")
#' checkDate("2017-05-40")

我正在使用 devtools 1.13.2 和 roxygen2 6.0.1,我认为这两个版本在发布时都是最新的。

我有其他包使用相同的 devtools/roxygen2 组合,但以前从未见过它无法在其范围内的 @examples 中找到函数名称。

其他人似乎经历过与this question 更新类似的事情,但我看不到有人说如何修复它。

【问题讨论】:

    标签: r devtools roxygen2


    【解决方案1】:

    我的猜测是你需要在Roxygen注释中#' @export该函数,否则该函数没有导出到包的命名空间,找不到。

    【讨论】:

    • 谢谢。您是否知道在不公开函数的情况下将示例包含在文档中的任何方法? (对于包的其他开发者)
    • 编辑:我想这不是必需的 - 可以只包括 cmets。
    • @Serenthia 你可以试试pkg:::function,然后你就不用公开这个函数了。
    • 使用pkg:::function 方法,您可能会收到a warning, and it may stop the package being accepted on CRAN
    • 是的,确实如此,可以做一些像do.call(":::", list(pkgname, functionname) 这样的技巧来克服这个问题,但无论如何不推荐......
    猜你喜欢
    • 2019-07-01
    • 1970-01-01
    • 2020-10-06
    • 2013-10-17
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 2018-07-20
    • 2016-05-16
    相关资源
    最近更新 更多