On Fri, Jan 13, 2012 at 6:12 AM, William Dunlap <wdun...@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 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.