[Rd] Capturing warnings with capture.output

Gabor Grothendieck ggrothendieck at gmail.com
Tue Aug 29 17:07:43 CEST 2006


Something like this which displays the warnings and also writes
them to out so that they are captured:

out <- capture.output(
   withCallingHandlers({
	print(1)
	warning("A warning.")
	print(2)
	warning("Another warning.")
	print(3)
   }, warning = function(x) cat(x$message, "\n"))
)

print(out)


On 8/29/06, hadley wickham <h.wickham at gmail.com> wrote:
> Is there any way to include warnings in the output from capture.output?  eg:
>
> a <- capture.output(warning("test"))
> all.equal(a, "Warning message: \n test ")
>
> Conceptually, this seems like redirecting stderr to stdout, or somehow
> changing warning to simple print it's output.  I've had a look at
> tryCatch and using a warning handler, but this terminates execution at
> the warning.
>
> Thanks,
>
> Hadley
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list