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












2














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 '18 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 '18 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 '18 at 10:08
















2














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 '18 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 '18 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 '18 at 10:08














2












2








2







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 '18 at 10:06









Konrad Rudolph

394k1017801025




394k1017801025










asked Nov 13 '18 at 9:43









José CarlosJosé Carlos

68821944




68821944








  • 1




    Sorry, but I don't see you assigning an object anywhere: x <- menu(competition=0, stats=0); print(x@competition)
    – Roland
    Nov 13 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 10:08












1 Answer
1






active

oldest

votes


















1














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',
    autoActivateHeartbeat: false,
    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









    1














    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


























      1














      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
























        1












        1








        1






        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 '18 at 10:03









        akrafakraf

        1,399823




        1,399823






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            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

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python