r - Is there a reason to prefer extractor functions to accessing attributes with $? -
on thread on crossvalidated, made following comment:
i suspect r question difference between working
s3
classes (that accessed via$
) &s4
classes (that accessed via@
)...
@gavin simpson subsequently commented:
@gung more spot on, solution not delve objects , rip out whatever feel learn use extractor functions, in case
coefficients()
or shorter aliascoef()
, incoef(fit)
i'm intrigued this. why using coef(model)
be better than model$coefficients[,1]
, example? (i recognize latter uglier , requires more typing, doubt that's reason intended.) case there isn't existing extractor function (e.g., accessing t-statistics)?
because author of package using free change underlying structure of model object without worrying breaking everyone's code.
obviously generalizes r core well. recommended use extractor functions because can sure return correct information, if function authors find necessary shuffle things around under hood.
maybe add more information 1 of elements of model list object, , changes order of everything? code break.
Comments
Post a Comment