Re: [R] What does class "call" mean? How do I make class "formula" into a "call"?
Thank you Bert and Prof. Ripley for your feedback. I did read the language documentation and it was not entirely clear to me, but I'm one of those people that has to read and digest something before it clicks. However, I did realize that the issue with "call"and "formula" was not the real reason why my program did not work. The real reason was much more trivial: I put the arguments inside the systemfit function out of order. Eventually, I figured it out. The good thing about this is that I learned about the existence of the R language documentation. Thank you again both! Rita = "If you think education is expensive, try ignorance."--Derek Bok > Date: Sat, 25 Jun 2011 05:59:40 +0100 > From: rip...@stats.ox.ac.uk > To: gunter.ber...@gene.com > CC: ritacarre...@hotmail.com > Subject: Re: [R] What does class "call" mean? How do I make class "formula" > into a "call"? > > This is really a misleading subject: it is already a call! From > ?class > > Many R objects have a ‘class’ attribute, a character vector giving > the names of the classes from which the object _inherits_. If the > object does not have a class attribute, it has an implicit class, > ‘"matrix"’, ‘"array"’ or the result of ‘mode(x)’ (except that > integer vectors have implicit class ‘"integer"’). > > So, simply remove the class if you want the mode: but anything which > needs to know this is call will be looking at the mode and not the > class. > > > zz <- ~x > > class(zz) > [1] "formula" > > mode(zz) > [1] "call" > > And see ?mode and ?call. Formulae and calls which are not formulae > are completely different: you cannot coerce one to the other. > > > On Fri, 24 Jun 2011, Bert Gunter wrote: > > > Well, this is kind of complicated. The first place you should go for > > help is not this list, but the R docs. Specfically ?call. This > > assumes familiarity with R's (S3) class system and language structure, > > however.. For this, I suggest ?UseMethod and consulting the R Language > > Definition Manual. > > > > Perhaps some brave soul on this list will attempt a short explanation > > in reply. But I am not (s)he. > > > > Cheers, > > Bert > > > > Oh -- as for specific suggestions, I think you need to do what the > > posting guide asks and provide a minimal reproducible example to give > > people a clearer idea of what's going on. > > > > On Fri, Jun 24, 2011 at 2:58 PM, Rita Carreira > > wrote: > >> > >> 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 format 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? And how do I make an object of type "formula" be > >> of type "call"? > >> Thank you so much!!!--Rita > >>> class(tabs) > >> [1] "list" > >>> class(tabs[1]) > >> [1] "list" > >>> class(tabs[[1]]) > >> [1] "formula"> class(eqSystem) > >> [1] "list" > >>> class(eqSystem[1]) > >> [1] "list" > >>> class(eqSystem[[1]]) > >> [1] "call" > >> > >> > >> Rita > >> = > >> "If you think education is expensive, try ignorance."--Derek Bok > >> > >> __ > >> 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. > >> > > > > > > > > -- > > "Men by nature long to get on to the ultimate truths, and will often > > be impatient with elementary studies or fight shy of them. If it were > > possible to reach the ultimate truths without the elementary studies > > usually prefixed to them, these would not be preparatory studies but > > superfluous diversions." > > > > -- Maimonides (1135-1204) > > > > Bert Gunter > > Genentech Nonclinical Biostatistics > > > > __ > > 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. > > > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UK Fax: +44 1865 272595 __ 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.
Re: [R] What does class "call" mean? How do I make class "formula" into a "call"?
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@cbs.dk Priv: pda...@gmail.com __ 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.
Re: [R] What does class "call" mean? How do I make class "formula" into a "call"?
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") 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.
Re: [R] What does class "call" mean? How do I make class "formula" into a "call"?
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") > 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". -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ 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.
Re: [R] What does class "call" mean? How do I make class "formula" into a "call"?
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. -- David. And how do I make an object of class "formula" be of class "call"? Thank you so much!!!--Rita class(tabs) [1] "list" class(tabs[1]) [1] "list" class(tabs[[1]]) [1] "formula"> class(eqSystem) [1] "list" class(eqSystem[1]) [1] "list" class(eqSystem[[1]]) [1] "call" Rita = "If you think education is expensive, try ignorance."--Derek Bok -- View this message in context: http://r.789695.n4.nabble.com/What-does-class-call-mean-How-do-I-make-class-formula-into-a-call-tp3623733p3623733.html Sent from the R help mailing list archive at Nabble.com. __ 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. 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.
[R] What does class "call" mean? How do I make class "formula" into a "call"?
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? And how do I make an object of class "formula" be of class "call"? Thank you so much!!!--Rita > class(tabs) [1] "list" > class(tabs[1]) [1] "list" > class(tabs[[1]]) [1] "formula"> class(eqSystem) [1] "list" > class(eqSystem[1]) [1] "list" > class(eqSystem[[1]]) [1] "call" Rita = "If you think education is expensive, try ignorance."--Derek Bok -- View this message in context: http://r.789695.n4.nabble.com/What-does-class-call-mean-How-do-I-make-class-formula-into-a-call-tp3623733p3623733.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] What does class "call" mean? How do I make class "formula" into a "call"?
Well, this is kind of complicated. The first place you should go for help is not this list, but the R docs. Specfically ?call. This assumes familiarity with R's (S3) class system and language structure, however.. For this, I suggest ?UseMethod and consulting the R Language Definition Manual. Perhaps some brave soul on this list will attempt a short explanation in reply. But I am not (s)he. Cheers, Bert Oh -- as for specific suggestions, I think you need to do what the posting guide asks and provide a minimal reproducible example to give people a clearer idea of what's going on. On Fri, Jun 24, 2011 at 2:58 PM, Rita Carreira wrote: > > 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 format 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? And how do I make an object of type > "formula" be of type "call"? > Thank you so much!!!--Rita >> class(tabs) > [1] "list" >> class(tabs[1]) > [1] "list" >> class(tabs[[1]]) > [1] "formula"> class(eqSystem) > [1] "list" >> class(eqSystem[1]) > [1] "list" >> class(eqSystem[[1]]) > [1] "call" > > > Rita > = > "If you think education is expensive, try ignorance."--Derek Bok > > __ > 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. > -- "Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions." -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics __ 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.
[R] What does class "call" mean? How do I make class "formula" into a "call"?
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 format 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? And how do I make an object of type "formula" be of type "call"? Thank you so much!!!--Rita > class(tabs) [1] "list" > class(tabs[1]) [1] "list" > class(tabs[[1]]) [1] "formula"> class(eqSystem) [1] "list" > class(eqSystem[1]) [1] "list" > class(eqSystem[[1]]) [1] "call" Rita = "If you think education is expensive, try ignorance."--Derek Bok __ 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.