Wrapper for creating custom metric functions with consistent interface
and error handling. The function may return one logical or numeric score, or
list(score = , feedback = ) for feedback-aware optimization.
Examples
# Custom length comparison
length_metric <- metric_custom(function(pred, exp) {
nchar(as.character(pred)) == nchar(as.character(exp))
}, name = "length_match")
# Custom scoring function
score_metric <- metric_custom(function(pred, exp) {
# Return value between 0 and 1
min(nchar(pred) / nchar(exp), 1)
})