[R] What does class "call" mean? How do I make class "formula" into a "call"?

peter dalgaard pdalgd at gmail.com
Sun Jun 26 21:53:15 CEST 2011


On Jun 26, 2011, at 00:10 , David Winsemius wrote:

> 
> On Jun 25, 2011, at 4:33 PM, peter dalgaard wrote:
> "
>> 
>> I.e., an unevaluated formulae expression (as in quote(y~x)) is class "call", as is an unclassed formula object. So it is pretty easy to have objects of class "formula" very similar to objects of class "call".
> 
> Not the first time I have stumbled on such matters. Chamber's SfDA would be one obvious place to study. Do yu have any others that pop to mind?   The last example suggests that mode and class can each be "call" so that 'call' is somehow more primitive than "function" or "formula".

Class and mode can also both be "function" or "numeric", but "formula" is not a mode. 

Historically, in S v3, all objects had a mode, but only some had a class, obtained by explicitly adding a "class" attribute. In S v4, the convention that all objects have a class was introduced, and in many cases an object's mode was promoted to become its class (but matrices became of class "matrix"). 

You can learn a lot by simple experimentation. E.g., it may be useful to know that call objects are isomorphic to lists and try things like 

u <- quote(1+3*4)
u[[1]]
u[[2]]
u[[3]]
u[[3]][[1]]


etc. Beware of "false friends": things that look alike but are different, e.g. the call quote(y~x) and the formula that results from evaluating it.

> And by way of directly addressing the OP's questions, it sounds as though applying unclass() to the formula objects might be attempted?

Or evaluating the call, or using as.formula() on it.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list