debugme icon indicating copy to clipboard operation
debugme copied to clipboard

still calculating unused debugs?

Open r2evans opened this issue 4 years ago • 1 comments

Q: when a "!DEBUG ..." message does not meet the !-threshold, why is its `expression` still evaluated?

.onLoad <- function(libname, pkgname) {
  if (requireNamespace("debugme", quietly = TRUE)) {
    # https://github.com/r-lib/debugme/issues/26#issuecomment-773615879
    get(".onLoad", asNamespace("debugme"))(libname, pkgname)
    debugme::debugme()
  }
}

#' @export
testme <- function(...) {
  msg <- "!DEBUG This is a test of debug level `0+1`"
  message(msg)
  msg <- "!!DEBUG This is a test of debug level `0+2`"
  message(msg)
  TRUE
}

Sys.setenv(DEBUGME="!mypackage")
devtools::document()
testme()
# mypackage This is a test of debug level 1 +5872ms 
# This is a test of debug level 1
# !!DEBUG This is a test of debug level 2
# [1] TRUE

I expected the first expression `0+1` to be evaluated, since it should be displayed. But I expected the second msg with `0+2` to instead message the raw string. This is the output I expected:

testme()
# mypackage This is a test of debug level 1 +5872ms 
# This is a test of debug level 1
# !!DEBUG This is a test of debug level `0+2`
# [1] TRUE

(I'm not suggesting that every use of "!DEBUG" will have a corresponding message or such (by definition of this package).)

sessionInfo()
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.0.3

r2evans avatar Feb 10 '21 23:02 r2evans

You are right, it should not evaluate the statements that are not printed.

gaborcsardi avatar Feb 11 '21 08:02 gaborcsardi