is there an equivalent for #ifdef (C langage) in R
On Fri, Jan 13, 2012 at 6:12 AM, William Dunlap <wdunlap at tibco.com> wrote:
You could put your debug-only code into a function calls like
? ifDebug(diagnosticPlot(c))
and
? ifDebug({
? ? ? ?tmp <- timeConsumingFunction(c)
? ? ? ?stopifnot(tmp < 1.0)
? })
When you want debug output define ifDebug as
? ifDebug <- function(expr) force(expr)
and when you don't want it define it as
? ifDebug <- function(expr) NULL
Because of lazy evaluation, the expression won't get evaluated
in the latter case.
This is a nice solution, for the question as posted. For other uses of #ifdef, it might be worth noting that it is less tolerant of syntax errors than #ifdef is, since the expression has to parse, not just tokenize. -thomas
Thomas Lumley Professor of Biostatistics University of Auckland