# NOT RUN {
# Changing a node component happens in place and can have side
# effects. Let's create a language object and a copy of it:
lang <- quote(foo(bar))
copy <- lang
# Using R's builtin operators to change the language tree does not
# create side effects:
copy[[2]] <- quote(baz)
copy
lang
# On the other hand, the CAR and CDR operators operate in-place. Let's
# create new objects since the previous examples triggered a copy:
lang <- quote(foo(bar))
copy <- lang
# Now we change the argument pairlist of `copy`, making sure the new
# arguments are NULL-terminated:
mut_node_cdr(copy, node(quote(BAZ), NULL))
# Or equivalently:
mut_node_cdr(copy, pairlist(quote(BAZ)))
copy
# The original object has been changed in place:
lang
# }
Run the code above in your browser using DataLab