2

I have a warning message I want to display only once during a session. Is there a fancy way to do this that doesn't involve storing a new object in the environment and checking it's value each time?

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

Created on 2020-03-12 by the reprex package (v0.3.0)

jzadra
  • 4,012
  • 2
  • 26
  • 46
  • 2
    [https://stackoverflow.com/questions/24812271/r-functions-print-warning-only-on-first-call-of-function](https://stackoverflow.com/questions/24812271/r-functions-print-warning-only-on-first-call-of-function) Maybe this will help – astrofunkswag Mar 12 '20 at 22:27
  • @astrofunkswag that's what I was after, thanks! – jzadra Mar 12 '20 at 23:02

0 Answers0