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:
What am I doing wrong? How can I get access to competition
or stats
?
r oop s4
add a comment |
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:
What am I doing wrong? How can I get access to competition
or stats
?
r oop s4
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
add a comment |
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:
What am I doing wrong? How can I get access to competition
or stats
?
r oop s4
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:
What am I doing wrong? How can I get access to competition
or stats
?
r oop s4
r oop s4
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
add a comment |
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
add a comment |
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))
add a comment |
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))
add a comment |
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))
add a comment |
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))
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))
answered Nov 13 at 10:03
akraf
1,378622
1,378622
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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