Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

still calculating unused debugs? #43

Open
r2evans opened this issue Feb 10, 2021 · 1 comment
Open

still calculating unused debugs? #43

r2evans opened this issue Feb 10, 2021 · 1 comment
Labels
bug an unexpected problem or unintended behavior

Comments

@r2evans
Copy link

r2evans commented Feb 10, 2021

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
@gaborcsardi
Copy link
Member

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

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants