Condition | Explanation |
---|---|
message |
A generic notification/diagnostic message produced by the message() function; execution of the function continues. |
warning |
An indication that something is wrong but not necessarily fatal; execution of the function continues. Warnings are generated by the warning() function. |
error |
An indication that a fatal problem has occurred and execution of the function stops. Errors are produced by the stop() function. |
2 Message, Warning, Error
2.1 Conditions
We can handle warnings
and errors
with functions like try()
, tryCatch()
and withCallingHandlers()
Functions like suppressWarnings()
and supressMessages()
can control what messages you wish to see while using R.
2.2 Function correctly runs
- All the following run of the function
log
is correct.
2.3 Function run shows warning
- The following run of the function
log
will givewarning()
Warning message: In log(-5) : NaNs produced
Warning message: NaNs produced
2.4 Function runs shows error
The following run of the function
log
will giveerror
The functions often used to generate errors within a funciton are:
stop()
,stopifnot()
,abort()
Error in log("A") : non-numeric argument to mathematical function
Error in log(10, base = "e") : non-numeric argument to mathematical function
Error in log(10, base = exp) : non-numeric argument to mathematical function
2.5 Function runs
Similar behaviour may be observed in Python function run
However, remember that the behaviour may change based on libraries used
Code
import math
# Correct
10)
math.log(1)
math.log(10)
math.log2(
# Error
-5)
math.log(0)
math.log("A")
math.log(
import numpy as np
# Correct
0) np.log(