data.table-condition-classes {data.table}R Documentation

Condition Handling with Classed Conditions

Description

data.table provides specific condition classes for common operations, making it easier to handle conditions programmatically. This is particularly useful when writing robust code or packages that use data.table. Relying on the exact text of condition messages is fragile (it is not uncommon to change the wording slightly, or for the user's session not to be in English); prefer using the signal class where possible.

Details

Available Condition Classes

data.table provides the following specific condition classes:

Error Classes:

Warning Classes:

Backward Compatibility

All condition classes inherit from base R's condition system, so existing tryCatch(..., error = ...) code continues to work unchanged. The new classes simply provide more specific handling options when needed.

See Also

tryCatch, test, https://adv-r.hadley.nz/conditions.html

Examples

    
# Handle missing column errors specifically
DT <- data.table(a = 1:3, b = 4:6)
tryCatch({
  setkey(DT, nonexistent_col)
}, dt_missing_column_error = function(e) {
  cat("Missing column detected:", conditionMessage(e), "\n")
}, error = function(e) {
  cat("Other error:", conditionMessage(e), "\n")
})

[Package data.table version 1.17.99 Index]