【问题标题】:menu() cannot be used non-interactively in Rmenu() 不能在 R 中以非交互方式使用
【发布时间】:2021-07-02 22:28:18
【问题描述】:

当我使用devtools::check() 构建和检查包时测试函数时,它会抛出错误Error: menu() cannot be used non-interactively

下面是一个小示例代码。

yes <- c("Yes", "Definitely", "Positive", "For sure", "Yup", "Yeah",
         "Absolutely")
no <- c("Not sure", "Not now", "Negative", "No", "Nope", "Absolutely not")

ask_confirmation <- function(title = NULL, positive = yes, negative = no) {
    options <- c(sample(positive, 1), sample(negative, 2)) # Mix which ones
    options <- sample(options, 3) # Random order
    sel <- menu(options, title = title)
    invisible(c("Cancel", options)[sel + 1])
}

如何克服这个问题?任何帮助将不胜感激。

【问题讨论】:

    标签: r unit-testing testing devtools


    【解决方案1】:

    我假设您正在测试自己的包。如果是这样,您可以将有问题的示例(调用menu())放在\donttest{ } 块中。

    Writing R Extensions

    【讨论】:

    • \donttest { } 用于文档。我认为这不是我正在寻找的答案。仅供参考,添加了一个示例供您参考。谢谢:)
    • 是的,它在文档中。那(在\examples{} 下)是我期望调用ask_confirmation 的地方(并且没有其他地方)。
    • 我在我的包中使用ask_conferamtion,我也在调用其他函数。所以我不确定如何将我的函数放在\examples{ } 下。
    • 您可以在所有示例中使用\examples{\donttest{ examples here } },或任何(间接)调用ask.confirmation
    • 这就是?menu本身所做的事情
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    相关资源
    最近更新 更多