Learn R Programming

quickcode (version 1.0.4)

has.error: Check if a call or expression produces errors

Description

Whether a function or series of calls results in error

Usage

has.error(...)

Value

boolean value to indicate if the expression produces errors

Arguments

...

the expression or function calls

Examples

Run this code
# this should not produce error
# so the function result should be FALSE
has.error({
  x = 8
  y = number(10)
  res = x + y
})

# this should produce the following error
# Error in x + y : non-numeric argument to binary operator
# so the function result should be TRUE
has.error({
  x = 8
  y = "random"
  res = x + y
})

# this should result in error because
# the dataset does not contain a "rpkg.net" column
# the result should be TRUE
df1 = mtcars
has.error(df1[,"rpkg.net"])

Run the code above in your browser using DataLab