Laurent Gautier
2023-Apr-23 17:33 UTC
[Rd] Warnings created during R_eval or R_tryEval not shown before R ending or R error.
Hi, I have an embedded R, with the evaluation of expressions happening over time during the lifespan of the process. I tried either `R_eval()` and `R_tryEval()` for the evaluation. The issue I have is that the processing of warnings does not happen until the process exits and/or R is shut down. Evaluating `warnings()` returns NULL (NILSXP). It seems like the warnings are stuck in a list out of `warnings()`'s reach, waiting to be processed. I cannot seem to find why or how to force that to happen. The embedded R is interactive (R_Interactive is 1). Moreover, when the evaluation of another R expression after the warnings results in an R error I get the error message shown followed by pending warnings. When tracing what happens during an error I found that verrorcall_dflt() in src/main/errors.c calls PrintWarnings(). That function is not part of R's C-API though. Would anyone have a suggestion about what I am missing? Best, Laurent [[alternative HTML version deleted]]
Ivan Krylov
2023-Apr-26 10:23 UTC
[Rd] Warnings created during R_eval or R_tryEval not shown before R ending or R error.
? Sun, 23 Apr 2023 13:33:16 -0400 Laurent Gautier <lgautier at gmail.com> ?????:> When tracing what happens during an error I found that > verrorcall_dflt() in src/main/errors.c calls PrintWarnings(). That > function is not part of R's C-API though.I've tried reading the source code and came to a similar conclusion. PrintWarnings() is required for warnings() to work because it creates the last.warning variable for warnings() to access. When driving an embedded R, R_ReplDLLdo1() will call it for you between expressions it processes, but there doesn't seem to be a way to call it yourself. Interestingly, there is .Internal(printDeferredWarnings()) which eventually calls PrintWarnings(), but it's not exported as an API, only used in a few places like try(). Would it help to run with options(warn = 1)? I think that a different code path is taken in this case, which should emit warnings even without a working REPL. warnings() would still be empty, unfortunately. -- Best regards, Ivan