![](https://static.isu.pub/fe/default-story-images/news.jpg?width=720&quality=85%2C50)
1 minute read
Adding Data to Your Package ���������������������������������������������������������������������������������������
Chapter 10 ■ ObjeCt Oriented prOgramming
## $frame ## y x ## 1 5.9784195 1.73343698 ## 2 0.5044947 -0.45442222 ## 3 -3.6050449 -1.47534377 ## 4 1.7420036 0.81883381 ## 5 -0.9105827 0.03838943 ## 6 -3.1266983 -1.14989951 ## 7 5.9018405 1.78225548 ## 8 2.2878459 1.29476972 ## 9 1.0121812 0.39513461 ## 10 -1.7562905 -0.72161442 ## ## $mean ## [,1] ## (Intercept) 0.2063805 ## x 2.5671043 ## ## $covar ## (Intercept) x ## (Intercept) 0.07399730 -0.01223202 ## x -0.01223202 0.05824769
Advertisement
It collects the relevant data of a model fit like this together in a list, so we always know we are working on the values that belong together. This makes further analysis of the fitted model much easier to program.
Classes
The output we got when we wrote:
model
is what we get if we call the print function on a list. It just shows us everything that is contained in the list. The print function is an example of a polymorphic function, however, so when you call print(x) on an object x, the behavior depends on the class of the object x.
If you want to know what class an object has, you can use the class function:
class(model) ## [1] "list"
If you want to change it, you can use the class<- replacement function:
class(model) <- "blm"
You can use any name for a class; here I’ve used blm for Bayesian linear model.
By convention, we usually call the class and the function that creates elements of that class the same name, so since we are creating this type of object with the blm function, convention demands that we call the class of the object blm as well. It is just a convention, though, and you can call the class anything.
259