Hello, I can't figure out how to call the sayMyNameIs function from within RCPersonAcc class
get
# Error in eval(ei, envir) : attempt to apply non-function
Was trying to follow these resources http://charlotte-ngs.github.io/RExperimentsWithS4RC/ExperimentsWithS4AndRef.html https://bookdown.org/rdpeng/RProgDA/object-oriented-programming.html
Add this (remove the function from the setRefClass call) and it will work
bob <- RCPersonAcc$methods(sayMyNameIs = function() {
cat(paste0("My name is ", givenName, ".\n"))
}
)
bob$sayMyNameIs()
since the function will be defined after the bob <- RCPersonAcc$accessors(c("givenName", "familyName", "emailAddress", "yearOfBirth")) line and you also don't have to do the .self referencing anymore. The section mentioned above explains it very well.
@300_bananas under Introduction | Advanced R you will find an overview about OOP in R by one of the most prolific R developers Hadley Wickham @hadley (author of ggplot2 -and most of the stuff in the tidyverse-, devtools, httr etc).
So given your background probably the R6 approach will feel by far the most natural - since it is the closest that you will come to classic OOP style of programming. Only downside - it is an extra package (has minimal dependencies).
The S7 approach is a new experimental one trying to combine the strengths of S3 and S4. Here the talk by Hadley for those who are intersetd https://www.youtube.com/watch?v=P3FxCvSueag (at the time of the recording it was still named R7 but they changed it to S7).