What does the “slot doesn't exist” error message mean?











up vote
2
down vote

favorite












I'm trying to write an object and access to his parameters. I've got two files, menus.R, where I define the object, and main.R, where I use the object and try to access to a slot (parameter).



The code of both files are next:



menus.R



menu <- setClass("menu", slots=list(competition="numeric", stats="numeric"))
setMethod("show", "menu", function(object){
while (TRUE){
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option)){
if (option == 1){
object@competition <- 14
}
if (option == 2){
object@competition <- 22
}
if (option == 3){
object@competition <- 23
}
readline("Espera ...")
if (option == 0)
break
}else{
readline("No es un número. Pulsa una tecla para introducir otra opción.")
}
}
})


main.R



menu(competition=0, stats=0)
print(menu@competition)
getClass(class(menu))


When I call menu(competition=0, stats=0) I can see what the method show gives me to me. This is correct. In show method I assign a value to competition. When I exit from show method the next instruction is print(menu@competition) and here is where I've got this error:




Error in print(menu@competition) : there is no a slot with name
"competition" for this object class "classGeneratorFunction"




Then with getClass(class(menu)) I've got this:



enter image description here



What am I doing wrong? How can I get access to competition or stats?










share|improve this question




















  • 1




    Sorry, but I don't see you assigning an object anywhere: x <- menu(competition=0, stats=0); print(x@competition)
    – Roland
    Nov 13 at 9:59










  • Side note: please don't post images of code or text, just copy and paste the text itself and format as code block
    – akraf
    Nov 13 at 10:05










  • Please take a moment to review my changes to your question and learn about the formatting options on Stack Overflow.
    – Konrad Rudolph
    Nov 13 at 10:08















up vote
2
down vote

favorite












I'm trying to write an object and access to his parameters. I've got two files, menus.R, where I define the object, and main.R, where I use the object and try to access to a slot (parameter).



The code of both files are next:



menus.R



menu <- setClass("menu", slots=list(competition="numeric", stats="numeric"))
setMethod("show", "menu", function(object){
while (TRUE){
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option)){
if (option == 1){
object@competition <- 14
}
if (option == 2){
object@competition <- 22
}
if (option == 3){
object@competition <- 23
}
readline("Espera ...")
if (option == 0)
break
}else{
readline("No es un número. Pulsa una tecla para introducir otra opción.")
}
}
})


main.R



menu(competition=0, stats=0)
print(menu@competition)
getClass(class(menu))


When I call menu(competition=0, stats=0) I can see what the method show gives me to me. This is correct. In show method I assign a value to competition. When I exit from show method the next instruction is print(menu@competition) and here is where I've got this error:




Error in print(menu@competition) : there is no a slot with name
"competition" for this object class "classGeneratorFunction"




Then with getClass(class(menu)) I've got this:



enter image description here



What am I doing wrong? How can I get access to competition or stats?










share|improve this question




















  • 1




    Sorry, but I don't see you assigning an object anywhere: x <- menu(competition=0, stats=0); print(x@competition)
    – Roland
    Nov 13 at 9:59










  • Side note: please don't post images of code or text, just copy and paste the text itself and format as code block
    – akraf
    Nov 13 at 10:05










  • Please take a moment to review my changes to your question and learn about the formatting options on Stack Overflow.
    – Konrad Rudolph
    Nov 13 at 10:08













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to write an object and access to his parameters. I've got two files, menus.R, where I define the object, and main.R, where I use the object and try to access to a slot (parameter).



The code of both files are next:



menus.R



menu <- setClass("menu", slots=list(competition="numeric", stats="numeric"))
setMethod("show", "menu", function(object){
while (TRUE){
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option)){
if (option == 1){
object@competition <- 14
}
if (option == 2){
object@competition <- 22
}
if (option == 3){
object@competition <- 23
}
readline("Espera ...")
if (option == 0)
break
}else{
readline("No es un número. Pulsa una tecla para introducir otra opción.")
}
}
})


main.R



menu(competition=0, stats=0)
print(menu@competition)
getClass(class(menu))


When I call menu(competition=0, stats=0) I can see what the method show gives me to me. This is correct. In show method I assign a value to competition. When I exit from show method the next instruction is print(menu@competition) and here is where I've got this error:




Error in print(menu@competition) : there is no a slot with name
"competition" for this object class "classGeneratorFunction"




Then with getClass(class(menu)) I've got this:



enter image description here



What am I doing wrong? How can I get access to competition or stats?










share|improve this question















I'm trying to write an object and access to his parameters. I've got two files, menus.R, where I define the object, and main.R, where I use the object and try to access to a slot (parameter).



The code of both files are next:



menus.R



menu <- setClass("menu", slots=list(competition="numeric", stats="numeric"))
setMethod("show", "menu", function(object){
while (TRUE){
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option)){
if (option == 1){
object@competition <- 14
}
if (option == 2){
object@competition <- 22
}
if (option == 3){
object@competition <- 23
}
readline("Espera ...")
if (option == 0)
break
}else{
readline("No es un número. Pulsa una tecla para introducir otra opción.")
}
}
})


main.R



menu(competition=0, stats=0)
print(menu@competition)
getClass(class(menu))


When I call menu(competition=0, stats=0) I can see what the method show gives me to me. This is correct. In show method I assign a value to competition. When I exit from show method the next instruction is print(menu@competition) and here is where I've got this error:




Error in print(menu@competition) : there is no a slot with name
"competition" for this object class "classGeneratorFunction"




Then with getClass(class(menu)) I've got this:



enter image description here



What am I doing wrong? How can I get access to competition or stats?







r oop s4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 10:06









Konrad Rudolph

391k1017711021




391k1017711021










asked Nov 13 at 9:43









José Carlos

66621944




66621944








  • 1




    Sorry, but I don't see you assigning an object anywhere: x <- menu(competition=0, stats=0); print(x@competition)
    – Roland
    Nov 13 at 9:59










  • Side note: please don't post images of code or text, just copy and paste the text itself and format as code block
    – akraf
    Nov 13 at 10:05










  • Please take a moment to review my changes to your question and learn about the formatting options on Stack Overflow.
    – Konrad Rudolph
    Nov 13 at 10:08














  • 1




    Sorry, but I don't see you assigning an object anywhere: x <- menu(competition=0, stats=0); print(x@competition)
    – Roland
    Nov 13 at 9:59










  • Side note: please don't post images of code or text, just copy and paste the text itself and format as code block
    – akraf
    Nov 13 at 10:05










  • Please take a moment to review my changes to your question and learn about the formatting options on Stack Overflow.
    – Konrad Rudolph
    Nov 13 at 10:08








1




1




Sorry, but I don't see you assigning an object anywhere: x <- menu(competition=0, stats=0); print(x@competition)
– Roland
Nov 13 at 9:59




Sorry, but I don't see you assigning an object anywhere: x <- menu(competition=0, stats=0); print(x@competition)
– Roland
Nov 13 at 9:59












Side note: please don't post images of code or text, just copy and paste the text itself and format as code block
– akraf
Nov 13 at 10:05




Side note: please don't post images of code or text, just copy and paste the text itself and format as code block
– akraf
Nov 13 at 10:05












Please take a moment to review my changes to your question and learn about the formatting options on Stack Overflow.
– Konrad Rudolph
Nov 13 at 10:08




Please take a moment to review my changes to your question and learn about the formatting options on Stack Overflow.
– Konrad Rudolph
Nov 13 at 10:08












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You are confusing the object constructor with the object itself.



menu(competition = 0, stats=0) generates you a new object of class menu, but you fail to save it somewhere, so it prints on the screen. Therefore your first, correct output.



But then, you want to manipulate the object. But you didn't save it! Instead, you try to manipulate the "object factory", menu(). The Type of the "object factory" is classGeneratorFunction, that's what you see.



This should work:



myMenuObject <- menu(competition=0, stats=0)
print(myMenuObject)
print(myMenuObject@competition)
getClass(class(myMenuObject))





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278051%2fwhat-does-the-slot-doesnt-exist-error-message-mean%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    You are confusing the object constructor with the object itself.



    menu(competition = 0, stats=0) generates you a new object of class menu, but you fail to save it somewhere, so it prints on the screen. Therefore your first, correct output.



    But then, you want to manipulate the object. But you didn't save it! Instead, you try to manipulate the "object factory", menu(). The Type of the "object factory" is classGeneratorFunction, that's what you see.



    This should work:



    myMenuObject <- menu(competition=0, stats=0)
    print(myMenuObject)
    print(myMenuObject@competition)
    getClass(class(myMenuObject))





    share|improve this answer

























      up vote
      1
      down vote



      accepted










      You are confusing the object constructor with the object itself.



      menu(competition = 0, stats=0) generates you a new object of class menu, but you fail to save it somewhere, so it prints on the screen. Therefore your first, correct output.



      But then, you want to manipulate the object. But you didn't save it! Instead, you try to manipulate the "object factory", menu(). The Type of the "object factory" is classGeneratorFunction, that's what you see.



      This should work:



      myMenuObject <- menu(competition=0, stats=0)
      print(myMenuObject)
      print(myMenuObject@competition)
      getClass(class(myMenuObject))





      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        You are confusing the object constructor with the object itself.



        menu(competition = 0, stats=0) generates you a new object of class menu, but you fail to save it somewhere, so it prints on the screen. Therefore your first, correct output.



        But then, you want to manipulate the object. But you didn't save it! Instead, you try to manipulate the "object factory", menu(). The Type of the "object factory" is classGeneratorFunction, that's what you see.



        This should work:



        myMenuObject <- menu(competition=0, stats=0)
        print(myMenuObject)
        print(myMenuObject@competition)
        getClass(class(myMenuObject))





        share|improve this answer












        You are confusing the object constructor with the object itself.



        menu(competition = 0, stats=0) generates you a new object of class menu, but you fail to save it somewhere, so it prints on the screen. Therefore your first, correct output.



        But then, you want to manipulate the object. But you didn't save it! Instead, you try to manipulate the "object factory", menu(). The Type of the "object factory" is classGeneratorFunction, that's what you see.



        This should work:



        myMenuObject <- menu(competition=0, stats=0)
        print(myMenuObject)
        print(myMenuObject@competition)
        getClass(class(myMenuObject))






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 10:03









        akraf

        1,378622




        1,378622






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278051%2fwhat-does-the-slot-doesnt-exist-error-message-mean%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents