When defining classes, does R have any notion of private vs public slots?
If there is no strict feature for this in the language, is there a common naming scheme?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EDIT :
To give a bit of history: In the setClass function an option ‘access’ was provided to create so-called ‘privileged slots’ that could only be accessed through getters and setters provided with the class. This would allow to create private slots (by not providing a getter), but this feature has never been implemented. The help page of
?setClasscurrently reads :So there is no such thing as private and public slots, as through the
@notation every slot is reachable. And personally I’m very happy with that, as it allows me to use information from objects that is not readily reachible by using the getters and setters included in the package. It also allows me to economize heavy calculations by avoiding overhead created by getters and setters.I am not aware of any naming convention for making a distinction between public and “private” slots. You can make the distinction for yourself by preceding the “private” slots with a dot, but that has no effect on how that slots behave. It’s also not common practice, as most R programmers don’t care about public and private slots. They just don’t provide getters and setters for slots that the average user shouldn’t reach.
To give a trivial example : the following creates a class with two slots, and a getter and setter for only one slot.
You can also set a
showmethod that just doesn’t print out the hidden slot:This gives the following normal use :
But the .ahiddenslot is still reachable: