WARNING message when run Rscript from command line
1
1
Entering edit mode
4.7 years ago
dpc ▴ 250

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 • 2.2k views
ADD COMMENT
2
Entering edit mode
4.7 years ago

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

ADD COMMENT

Login before adding your answer.

Traffic: 2161 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6