[R] warning.expression?

25 views
Skip to first unread message

Cole Arendt

unread,
Apr 20, 2017, 10:38:02 AM4/20/17
to r-h...@stat.math.ethz.ch
> It seems a bit dumb that warning.expression functions can only say
> "Hey, something a bit iffy may have ocurred, but I dont know what and I
> dont know where!". Maybe there's something in that cptr->cloenv that can
> tell you...


The way that I intend to begin using this is with non-standard evaluation and traceback() to determine the context of all warnings in a use case similar to yours. In particular, traceback(0) will print the entire call stack. As a result, wrapping the logging / printing into a substitute() call will cause the expression to be evaluated appropriately on a warning event. If you want to skip a few messages in the call stack, change the integer you are passing (i.e. traceback(6) will ignore 6 messages at the end of the call stack - where internals are being called).


Note that I am using the logging package here, which seems that it might fit your use case nicely, if configured appropriately. Documentation here: http://logging.r-forge.r-project.org/


options( warning.expression = {
substitute(
for (m in rev(traceback(0))) {
logging::logwarn(m)
}
)
}
)



[[alternative HTML version deleted]]

______________________________________________
R-h...@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
Reply all
Reply to author
Forward
0 new messages