Robert Wilkins
2009-Oct-10 07:21 UTC
[R] easy way to find all extractor functions and the datatypes of what they return
Am I asking for too much: for any object that a stat proc returns ( y <- lm( y~x) , etc ) ) , is there a super convenient function like give_all_extractors( y ) that lists all extractor functions , the datatype returned , and a text descriptor field ("pairwisepval" "lsmean" etc) That would just be so convenient. What are my options for querying an object so that I can quickly learn the extractor functions to pull out the data and manipulate it? Will the datatypes returned usually be named vectors and named matrices, indiced by categorical values in the data ( "Male" "Female" "Placebo" "DrugB" etc )? If they are indexed by 1 , 2 , 3 , 4 , it's easier to lose track. thanks a bunch in advance
Peter Ehlers
2009-Oct-10 12:33 UTC
[R] easy way to find all extractor functions and the datatypes of what they return
Robert Wilkins wrote:> Am I asking for too much: > for any object that a stat proc returns ( y <- lm( y~x) , etc ) ) , is there > a super convenient function like give_all_extractors( y ) that lists all > extractor functions , the datatype returned , and a text descriptor > field ("pairwisepval" "lsmean" etc)I think that you _are_ asing for too much. (But that's not to say that you shouldn't consider providing code for such a function yourself.)> > That would just be so convenient. > > What are my options for querying an object so that I can quickly learn > the extractor functions to pull out the data and manipulate it? > Will the datatypes returned usually be named vectors and named > matrices, indiced by categorical values in the data > ( "Male" "Female" "Placebo" "DrugB" etc )? If they are indexed by 1 , > 2 , 3 , 4 , it's easier to lose track.The way to learn about extractor functions is to read the help pages which you would surely do before using any function that you haven't used previously. ?lm, for example, would point you to coef, effects, residuals, fitted, vcov. (Be aware, however, that not all contributed packages provide help of the same calibre as does base R.) The other, highly recommended, way to learn about objects in R is the str() function. Use it often. As to your question about named objects, R is almost obsessive about preserving names. -Peter Ehlers> > thanks a bunch in advance > > ______________________________________________ > R-help at 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. > >
Gabor Grothendieck
2009-Oct-10 12:43 UTC
[R] easy way to find all extractor functions and the datatypes of what they return
Try this (where "lm" is the class of the lm output):> methods(class = "lm")[1] add1.lm* alias.lm* anova.lm case.names.lm* [5] confint.lm* cooks.distance.lm* deviance.lm* dfbeta.lm* [9] dfbetas.lm* drop1.lm* dummy.coef.lm* effects.lm* [13] extractAIC.lm* family.lm* formula.lm* hatvalues.lm [17] influence.lm* kappa.lm labels.lm* logLik.lm* [21] model.frame.lm model.matrix.lm plot.lm predict.lm [25] print.lm proj.lm* residuals.lm rstandard.lm [29] rstudent.lm simulate.lm* summary.lm variable.names.lm* [33] vcov.lm* Non-visible functions are asterisked On Sat, Oct 10, 2009 at 3:21 AM, Robert Wilkins <robstdev at gmail.com> wrote:> Am I asking for too much: > for any object that a stat proc returns ?( y <- lm( y~x) , etc ) ) , is there > a super convenient function like give_all_extractors( y ) that lists all > extractor functions , the datatype returned , and a text descriptor > field ("pairwisepval" "lsmean" etc) > > That would just be so convenient. > > What are my options for querying an object so that I can quickly learn > the extractor functions to pull out the data and manipulate it? > Will the datatypes returned usually be named vectors and named > matrices, indiced by categorical values in the data > ( "Male" "Female" ?"Placebo" "DrugB" etc )? If they are indexed by 1 , > 2 , 3 , 4 , it's easier to lose track. > > thanks a bunch in advance > > ______________________________________________ > R-help at 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. >