> student1 Student name: Fred Student grade: 98 78 76 86 > student1 Student name: Fred Student grade: 98 78 76 86 > typeof(student1) [1] "double" > class(student1) [1] "student" > print(student1) Student name: Fred Student grade: 98 78 76 86 > source('~/Desktop/classes.R') > addGrade.student(student1, 57) [1] 98 78 76 86 57 > attributes(student1) $name [1] "Fred" $class [1] "student" > source('~/Desktop/classes.R') > addGrade.student(student1, 57) Student name: Fred Student grade: 98 78 76 86 57 > student1 Student name: Fred Student grade: 98 78 76 86 > # This doesn't change student1! Must still use assignment statement > student1 <- addGrade.student(student1, 57) > student1 Student name: Fred Student grade: 98 78 76 86 57 > > # This way of looking at R data structures as 'objects' with functions that > # can edit or do things with that object has a name: > # Object-oriented programming > source('~/Desktop/classes.R') > getName.student(student1) [1] "Fred" > source('~/Desktop/classes.R') > setName.student(student1, "Jenny") Student name: Jenny Student grade: 98 78 76 86 57 > source('~/Desktop/classes.R') > doctor1 numeric(0) attr(,"class") [1] "doctor" > source('~/Desktop/classes.R') > doctor1 Doctor name: > doctor1 <- setName.doctor(doctor1, "Pepper") > doctor1 Doctor name: Dr. Pepper > source('~/Desktop/classes.R') > setName(student1, "Johnny") Student name: Johnny Student grade: 98 78 76 86 57 > setName(doctor1, "Johnny") Doctor name: Dr. Johnny > length(c(1, 2, 3)) [1] 3 > length(list(1,4,5)) [1] 3 > length("string") [1] 1 > # length(x) is an example of a generic function > # x can be of many differnt types > # and length(x) chooses the correct specific function in R to give the length for that type > # We don't care how those specific funtions work for each type. We just use length(x)! > print(student1) Student name: Fred Student grade: 98 78 76 86 57 > print(doctor1) Doctor name: > # Print is also a generic function > > student1 Student name: Fred Student grade: 98 78 76 86 57 > unclass(student1) [1] 98 78 76 86 57 attr(,"name") [1] "Fred" > source('~/Desktop/classes.R') > Student("Jimmy", c(67, 98, 45, 78)) Student name: Jimmy Student grade: 67 98 45 78 > jimmyStudent <- Student("Jimmy", c(67, 98, 45, 78)) > jimmyStudent Student name: Jimmy Student grade: 67 98 45 78