[R] Output of warnings inside the source function
Arkady.Sherman at ksu.ru
Sun Sep 11 21:36:59 CEST 2005
Uwe Ligges wrote:
> Arkady Sherman wrote:
>> Hello, all.
>> There is a problem to get an output of warnings() function to sink in
>> a file specified.
>> There are to files
>> 1. File "test" with content:
>> 2. and file "test_foo" with content:
>> options(warn = 1)
>> warning("Foo warning")
>> 3. If I run R as
>> "c:\Program Files\R\rw2011\bin\R.exe" --no-save < test > out.txt
>> the file "c:/temp/foo.txt" will contain nothing.
>> But I'd like it should contain the warning message "Foo warning".
>> Is the behavior a bug of R or there is another way to get it working.
> See ?sink how to handle messages such as warnings.
It's clear I could use sink(f, type="message"), but if I run "c:\Program
Files\R\rw2011\bin\R.exe" --no-save < test_foo > out.txt instead, the
warning is written to foo.txt without sinking with type="message". Also
the problem is that in the later case the warnings will appear in the
output file in places when just produced, but I need them to appear when
I call warnings().
The problem (and question) is that the last.warning variable has not
been set after the warning call (even when options(warn = 1) is defined)
and warnings() can't output it, so - is that a right behavior?
More information about the R-help