How to examine the code of a function in R that's object class sensitive

后端 未结 5 665
南笙
南笙 2020-12-07 15:35

I\'m trying to write a function to do a particular job (in my case, analyse a data set for outliers) so the first things I want to do is look at how other people have done s

5条回答
  •  有刺的猬
    2020-12-07 15:43

    For example, plot() will do different things depending on the object. You can see the specific plot functions (called methods) using plot.ts(), plot.lm(), etc. i.e., plot() will call plot.ts() if a ts object is passed. In general, plot.xxx() is applied to objects of class xxx. If there is no specific method for the class, then plot.default() is used.

    The function plot() is called a generic function because it can apply to many different classes. Other common generic functions are summary(), print() and predict().

    As Dirk says, it is well worth reading the documentation on S3 methods and classes.

提交回复
热议问题