menu() 不能在 R 中以非交互方式使用 [英] menu() cannot be used non-interactively in R
本文介绍了menu() 不能在 R 中以非交互方式使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 devtools::check()
构建和检查包时测试函数时,它抛出错误 Error: menu() cannot be used non-interactively
While testing a function when I use devtools::check()
to build and check the package it throws an error Error: menu() cannot be used non-interactively
下面是一个小的示例代码.
Below is a small example code.
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])
}
如何克服这个问题?任何帮助将不胜感激.
How to overcome this problem? Any help would be greatly appreciated.
推荐答案
我假设您正在测试自己的包.如果是这样,您可以将违规示例(调用 menu()
)放在 \donttest{ }
块中.
I am assuming your are testing your own package. If so, you can put the offending examples (that call menu()
) in a \donttest{ }
block.
参见编写 R 扩展
这篇关于menu() 不能在 R 中以非交互方式使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文