# Example with alternating patterns and replacements
expr_replace({ 1 + 2 }, {1}, {one}, {2}, {two})
# Example with patterns and replacements in a list
expr_replace({ 1 + 2 }, patterns = expr_list({1}, {2}),
replacements = expr_list({one}, {two}))
# Replace with captures
expr_replace({ 1 + 2 }, ~{ .A + .B }, { .A - .B })
# Function replacement with conditional logic
expr_replace({ x^2 + y^2 + z^3 }, { ..A ^ .N },
function(m) {
if (m$N == 2) substitute(square(A), m) else substitute(A ^ N, m)
})
Run the code above in your browser using DataLab