Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:01:31+00:00 2026-06-04T13:01:31+00:00

When defining classes, does R have any notion of private vs public slots? If

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:01:33+00:00Added an answer on June 4, 2026 at 1:01 pm

    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 ?setClass currently reads :

    access and version, included for compatibility with S-Plus, but
    currently ignored.


    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.

    setClass("Example",
      representation(
        aslot = "numeric",
        .ahiddenslot = "character"
      )
    )
    
    setGeneric("aslot", function(x) standardGeneric("aslot"))
    
    setMethod("aslot","Example",function(x){
        x@aslot
    })
    
    setGeneric("aslot<-", function(x,value) standardGeneric("aslot<-"))
    
    setMethod("aslot<-","Example",function(x,value){
        x@aslot <- value
        x
    })
    

    You can also set a show method that just doesn’t print out the hidden slot:

    setMethod("show","Example",function(object){
      cat("Example with value for aslot: ", object@aslot,"\n")
    })
    

    This gives the following normal use :

    > X <- new("Example",aslot=1,.ahiddenslot="b")
    > X
    Example with value for aslot:  1 
    > aslot(X)
    [1] 1
    > aslot(X) <- 3
    

    But the .ahiddenslot is still reachable:

    > slot(X,".ahiddenslot")
    [1] "b"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a question about what defining a class as public or private does.
I have the classes below: SuppliersRepository.cs (with the interface defining the method): public class
Possible Duplicate: Interface defining a constructor signature? I have a mixed hierarchy of classes
I have a framework which works this way: After defining some meta data, it
I am defining a custom tag htmlencoder. I have These files: WEB-INF/classes/HtmlEncoderTag.jar ,with a
If a Java class implements the Serializable interface but does not have a public
This is probably a silly mistake but I cant see it?! I have classes
I'm having some problems when defining inner classes in a Test class inherited from
I'm defining a DU for the various classes I use within HTML: type Class
Defining custom components in Facelets is easy and quick but there's one thing I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.