when I run an Rscript from command line I received an "warning" message like:
There were 14 warnings (use warnings() to see them)
But "warnings()" is useful only in R console. How can I see those warnings from command line?
when I run an Rscript from command line I received an "warning" message like:
There were 14 warnings (use warnings() to see them)
But "warnings()" is useful only in R console. How can I see those warnings from command line?
It somewhat depends on how the warnings are being produced - some functions may have specific options for suppressing / outputting warnings, for example.
The easiest approach is probably as elaborated HERE.
A quick example:
options(warn = 0)
log <- file('log.out', open = 'wt')
sink(log, type = 'message')
warning('warning!')
warning('Achtung!')
warning('Aviso!')
warning('Atenção!')
sink(type = 'message')
close(log)
Now execute it:
Rscript test.R
Warning message:
warning!
Warning message:
Achtung!
Warning message:
Aviso!
Warning message:
Atenção!
By the way, setting options(warn = 0)
just ensures that warnings will be issued. Setting it to options(warn = -1)
would mean that warnings are not even reported anywhere.
Kevin
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.