首页 > 解决方案 > R如何在会话中仅显示一次消息()?

问题描述

我有一条警告消息,我只想在会话期间显示一次。有没有一种不涉及在环境中存储新对象并每次检查它的值的奇特方法?

value <- 2
checkval <- function(x) if(x == 2) message("Warning, value is 2. This message will only be displayed once")

checkval(value)
#> Warning, value is 2. This message will only be displayed once

checkval(value) #second time, don't want it to display the warning.
#> Warning, value is 2. This message will only be displayed once

reprex 包于 2020-03-12 创建(v0.3.0)

标签: r

解决方案


推荐阅读