Not sure when introduced, but plot() now has a display argument that can be used to hide or display it.
plot()
display
plot(..., display = enablePlot ? display.all : display.none, ...)
would be equivalent to the forbidden
if enablePlot plot(...)