[Rd] Dropping RHS of a formula using NULL assignment
Blackwell, Matthew
mb|@ckwe|| @end|ng |rom gov@h@rv@rd@edu
Tue Dec 14 21:26:39 CET 2021
Hello all,
In attempting to create a one-sided formula from a two-sided formula,
I discovered that the following syntax will successfully complete this
operation:
> f <- y ~ x + z
> f[2] <- NULL
> f
~x + z
> str(f)
Class 'formula' language ~x + z
..- attr(*, ".Environment")=<environment: R_GlobalEnv>
In searching through the formula documentation, I couldn't find this
technique as documented and wondered whether or not it is expected and
if it makes sense to develop a package against the behavior. I'm using
R 4.1.0, but I see the same on R-devel (r81303). I asked on Twitter,
but someone thought this list might be a better venue.
Apologies if I missed some documentation and thanks in advance.
Cheers,
Matt
~~~~~~~~~~
Matthew Blackwell
Associate Professor of Government
Harvard University
https://www.mattblackwell.org
More information about the R-devel
mailing list