On Jun 25, 2011, at 4:33 PM, peter dalgaard wrote:


On Jun 25, 2011, at 15:24 , David Winsemius wrote:


On Jun 24, 2011, at 6:12 PM, StellathePug wrote:

Hello R Users!
I have a list called "tabs" that I would like to have the same structure as my list "eqSystem." The two look like they have the same structure but they are different because when I look at their attributes, class(eqSystem[[1]]) is "call" but class(tabs[[1]]) is "formula". I want to have class(tabs[[1]])
as a call too.

So what does "call" mean?

An as yet unevaluated function invocation with first as the named function followed by quoted arguments is a "call":

See the help(call) page:

f <- round
A <- 10.5
(g <- as.call(list(f, quote(A))))
.Primitive("round")(A)
eval(g)
[1] 10

call("mean", quote( c(1,2,3)))
mean(c(1, 2, 3))
eval( call("mean", quote( c(1,2,3))))
[1] 2

It seems very unlikely that a formula object could be coerced into a valid call simply by altering its class. To convince us otherwise you need to provide more information than you have supplied to the present. The results of str() on these objects might be a first step.

Actually, no. Any unevaluated expression in R is mode "call", unless atomic or symbol. It will also be class "call", unless expressedly overridden by an S3 class assignment. Notice that operators are really function calls.
I.e.

mode(quote(x+y))
[1] "call"
class(quote(x+y))
[1] "call"

But

class(quote(x))
[1] "name"
class(quote(3.14159))
[1] "numeric"

(This is why the R docs keep talking about "unevaluated expressions" instead of "call objects": They aren't always that.)

The "~" operator is also a function call. However, evaluating "~" returns an object which is the actual call assigned class "formula" (plus an environment attribute).

f <- y ~ x
class(f)
[1] "formula"
unclass(f)
y ~ x
attr(,".Environment")
<environment: R_GlobalEnv>
mode(f)
[1] "call"
class(unclass(f))
[1] "call"

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".

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



--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to