[R] easy way to find all extractor functions and the datatypes of what they return
David Winsemius
dwinsemius at comcast.net
Sat Oct 10 17:32:39 CEST 2009
Building on the two prior suggestions ( str() and methods() ) you
could write a function to get both the named components of an object
and the functions that work on its class. Using the example lm.D9 in
the help page for lm:
get_mths_str <- function(obj) c(functs =
list(methods(class=class(obj))),
components=list(names(lm.D9))
)
> get_mths_str(lm.D9)
$functs
[1] add1.lm* addterm.lm* alias.lm*
anova.lm attrassign.lm*
[6] boxcox.lm* case.names.lm* confint.lm*
cooks.distance.lm* deviance.lm*
[11] dfbeta.lm* dfbetas.lm* drop1.lm*
dropterm.lm* dummy.coef.lm*
[16] effects.lm* extractAIC.lm* family.lm*
formula.lm* hatvalues.lm
[21] influence.lm* kappa.lm labels.lm*
logLik.lm* logtrans.lm*
[26] model.frame.lm model.matrix.lm plot.lm
predict.lm print.lm
[31] proj.lm* residuals.lm rstandard.lm
rstudent.lm simulate.lm*
[36] summary.lm variable.names.lm* vcov.lm*
Non-visible functions are asterisked
$components
[1] "coefficients" "residuals" "effects" "rank"
"fitted.values" "assign"
[7] "qr" "df.residual" "contrasts" "xlevels"
"call" "terms"
[13] "model"
--
David
On Oct 10, 2009, at 8:43 AM, Gabor Grothendieck wrote:
> 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
--
>
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list