Skip to contents

Parses and evaluates expr in a restricted environment containing only the columns of df (parent: baseenv()). This isolates evaluation from the global environment, reducing scope for unintended side effects.

Usage

safe_eval_expr(df, expr)

Arguments

df

Data frame providing column names as variables.

expr

Character. Expression to evaluate (e.g., "BM > 1 & tmrsize > 19").

Value

Result of evaluating expr, or NULL on failure.

Note

eval(parse()) is used intentionally here. evaluate_comparison handles only single comparisons (e.g., "er <= 0"); this function is needed for the compound logical expressions produced by the ForestSearch subgroup enumeration algorithm (e.g., "er <= 0 & nodes > 3"). Evaluation is sandboxed: the environment contains only the columns of df with baseenv() as parent, so neither the global environment nor any package namespace is in scope. No user-supplied strings are evaluated; only internally-constructed subgroup definition strings reach this function.

See also

evaluate_comparison for the single-comparison operator-dispatch alternative that avoids eval(parse()).