This is a test version of Biostars. For the public version, visit https://www.biostars.org.
WARNING message when run Rscript 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?

r

1 answer

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:

test.R

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

log.out

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

Log in to answer this question.