[R] Why does debugging print() change output of function?
David Winsemius
dwinsemius at comcast.net
Wed Sep 10 07:13:52 CEST 2014
On Sep 9, 2014, at 4:07 PM, peter dalgaard wrote:
>
> On 07 Sep 2014, at 00:31 , David Winsemius <dwinsemius at comcast.net>
> wrote:
>
>> The goal:
>> to create a function modeled after `subset` (notorious for its non-
>> standard evaluation) that will take a series of logical tests as
>> unquoted expressions to be evaluated in the framework of a
>> dataframe environment and return a dataframe of logicals:
> ...
>
> A belated peep from the author of subset(): Don't!
>
> I think we learned the hard way by now that it is much easier to
> pass unevaluated expressions in the shape of formula objects or
> maybe expression objects. Lots of pain can be avoided by slipping in
> a simple "~".
It's taken me several years to understand why you are probably correct
in this regard. I needed to learn that `~` is actually a function that
creates a language object.
> is.function(`~`)
[1] TRUE
> is.language( ~ x > 5 & x < 10)
[1] TRUE
... and that it's rather easy to extract the object somewhat like but
not really an expression embedded in such an object:
> is.expression( ~ x > 5 & x < 10)
[1] FALSE
> is.call( (~ x > 5 & x < 10)[2] )
[1] TRUE
The task of learning the various types of language objects is not an
easy one.
--
David Winsemius, MD
Alameda, CA, USA
More information about the R-help
mailing list