[R] What is a expression good for?

Alberto Vieira Ferreira Monteiro albmont at centroin.com.br
Wed Feb 28 23:40:11 CET 2007


Bert Gunter wrote:
>
> An expression object is the output of parse(), and so is R's representation
> of a parsed expression. It is a type of list -- a parse tree for the
> expression. This means that you can actually find the sorts of things you
> mention by taking it apart as a list:
>
>> ex <- parse(text = "x + y")
>> ex
>
> expression(x + y)
>
>> class(ex)
>
> [1] "expression"
>
>> ex[[1]]
>
> x + y
>
Ok so far. But which magic did you use to infer that the next
instructions return something useful?

>> ex[[c(1,1)]]
>
> `+`
>
>> ex[[c(1,2)]]
>
> x
>
>> ex[[c(1,3)]]
>
> y
>
>
> There are few if any circumstances when one should do this: this is the job
> of the evaluator. There are also special tools available for when you
> really might want to do this sort of thing   -- eg. ?formula, ?terms for
> altering model specifications. But it is tricky to do right and in full
> generality -- e.g. ?eval and the above references for some of the issues.
>
I was thinking about doing symbolic algebra - or some tiny part of it.
R does not have a symbolic library, does it?

Alberto Monteiro



More information about the R-help mailing list