tryIt: Safely Evaluate an Expression

View source: R/tryIt.R

tryItR Documentation

Safely Evaluate an Expression

Description

Evaluates an expression and returns NULL if it fails, instead of throwing an error.

Usage

tryIt(x, silent = TRUE)

Arguments

x

An R expression to evaluate

silent

Logical; if TRUE suppresses error messages (default FALSE)

Details

This function is useful for safely evaluating expressions that might fail, particularly in loops or apply functions where you want to continue execution even if some operations fail.

Value

Returns the result of evaluating the expression if successful, NULL if it fails

Examples

# Successful evaluation
tryIt(1 + 1)

# Failed evaluation returns NULL
tryIt(log("a"))

# Suppress error messages
tryIt(log("a"), silent=TRUE)

laurieKell/FLCandy documentation built on April 17, 2025, 5:23 p.m.