0

I'd like to create warning/error log for the R script.
Please see below example:

setwd(tempdir())
zz <- file("all.Rout", open="wt")
    sink(zz, type="message")
    for (i in 1:30){
           log(i-50)
         }
    sink(type="message")
    close(zz)

I was expecting that it will enlist all warnings:
Warning messages:
1: In log(i - 50) : NaNs produced
2: In log(i - 50) : NaNs produced
3: In log(i - 50) : NaNs produced

However for the loop i in 1:30 there is only one line in the all.rout file:
There were 30 warnings (use warnings() to see them)

Any idea how to fix it?

I have created the code based on another topic:

Output error/warning log (txt file) when running R script under command line

1 Answer 1

2

Try options(warn=1)

From ?options:

'warn': sets the handling of warning messages.  If 'warn' is
      negative all warnings are ignored.  If 'warn' is zero (the
      default) warnings are stored until the top-level function
      returns.  If 10 or fewer warnings were signalled they will be
      printed otherwise a message saying how many were signalled.
      An object called 'last.warning' is created and can be printed
      through the function 'warnings'.  If 'warn' is one, warnings
      are printed as they occur.  If 'warn' is two or larger all
      warnings are turned into errors.
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.