-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS3ClassTuto.R
More file actions
31 lines (26 loc) · 1.18 KB
/
S3ClassTuto.R
File metadata and controls
31 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# You can set the class attribute using the class command.
# One thing to notice is that the class is a vector which
# allows an object to inherit from multiple classes, and
# it allows you to specify the order of inheritance for
# complex classes. You can also use the class command to
# determine the classes associated with an object.
# > bubba <- c(1,2,3)
# > bubba
# [1] 1 2 3
# >
# > class(bubba)
# [1] "numeric"
# >
# > class(bubba) <- append(class(bubba),"Flamboyancy")
# > class(bubba)
# [1] "numeric" "Flamboyancy"
# Note
#
# A new command, append, is used here. The first argument is a vector,
# and the function adds the following arguments to the end of the vector.
# One way to define a method for a class is to use the UseMethod command to
# define a hierarchy of functions that will react appropriately. The UseMethod
# command will tell R to look for a function whose prefix matches the current
# function, and it searches for a suffix in order from the vector of class names.
# In other words a set of functions can be defined, and the function that is actually
# called will be determined by the class name of the first object in the list of arguments.