Skip to content
Prev 60391 / 63424 Next

Dropping RHS of a formula using NULL assignment

On 14/12/2021 20:26, Blackwell, Matthew wrote:
See ?"~", which says

      A formula has mode ?call?.  It can be subsetted by ?[[?: the
      components are ?~?, the left-hand side (if present) and the
      right-hand side _in that order_.

That would suggest that

f <- y ~ x + z
f[[2]] <- NULL

was the documented way (and the one I would have used).   However, ?"[" says

      ?[? and ?[[? are sometimes applied to other recursive objects such
      as calls and expressions.  Pairlists are coerced to lists for
      extraction by ?[?, but all three operators can be used for
      replacement.