msg <- once(message)
msg("abc") # Prints.
msg("abc") # Silent.
msg <- once(message) # Starts over.
msg("abc") # Prints.
f <- function(){
innermsg <- once(message)
innermsg("efg") # Prints once per call to f().
innermsg("efg") # Silent.
msg("abcd") # Prints only the first time f() is called.
msg("abcd") # Silent.
}
f() # Prints "efg" and "abcd".
f() # Prints only "efg".
msg3 <- once(message, max_entries=3)
msg3("a") # 1 remembered.
msg3("a") # Silent.
msg3("b") # 2 remembered.
msg3("a") # Silent.
msg3("c") # 3 remembered.
msg3("a") # Silent.
msg3("d") # "a" forgotten.
msg3("a") # Printed.
msg2s <- once(message, expire_after=2)
msg2s("abc") # Prints.
msg2s("abc") # Silent.
Sys.sleep(1)
msg2s("abc") # Silent after 1 sec.
Sys.sleep(1.1)
msg2s("abc") # Prints after 2.1 sec.
Run the code above in your browser using DataLab