R: Object doesn't find custom function
I'm newbie in R and I want to create an object with his methods. I have defined my object and function with these code:
setClass("gComparativa", slots=list(data="ANY"))
show_graphic <- function(object) 0
setGeneric("show_graphic")
setMethod("show_graphic", "gComparativa", function(object){
})
I create and call the method with these code:
g <- new("gComparativa", data=data)
g.show_graphic()
But when I call the method I've this error:
Error in g.show_graphic() : This function cannot be found
"g.show_graphic"
What am I doing wrong? What can I define methods and call later?
r oop
add a comment |
I'm newbie in R and I want to create an object with his methods. I have defined my object and function with these code:
setClass("gComparativa", slots=list(data="ANY"))
show_graphic <- function(object) 0
setGeneric("show_graphic")
setMethod("show_graphic", "gComparativa", function(object){
})
I create and call the method with these code:
g <- new("gComparativa", data=data)
g.show_graphic()
But when I call the method I've this error:
Error in g.show_graphic() : This function cannot be found
"g.show_graphic"
What am I doing wrong? What can I define methods and call later?
r oop
1
Might be other issues and I'm not the most familiar with S4 but you don't call methods in R with dot notation like that, you just doshow_graphic(g)
. See more here adv-r.hadley.nz/s4.html#s4-generics
– Calum You
Nov 13 '18 at 23:25
1
@CalumYou Just saw your comment right after I posted my answer. I think technically your comment came first, so if you post as an answer I will delete.
– duckmayr
Nov 13 '18 at 23:27
add a comment |
I'm newbie in R and I want to create an object with his methods. I have defined my object and function with these code:
setClass("gComparativa", slots=list(data="ANY"))
show_graphic <- function(object) 0
setGeneric("show_graphic")
setMethod("show_graphic", "gComparativa", function(object){
})
I create and call the method with these code:
g <- new("gComparativa", data=data)
g.show_graphic()
But when I call the method I've this error:
Error in g.show_graphic() : This function cannot be found
"g.show_graphic"
What am I doing wrong? What can I define methods and call later?
r oop
I'm newbie in R and I want to create an object with his methods. I have defined my object and function with these code:
setClass("gComparativa", slots=list(data="ANY"))
show_graphic <- function(object) 0
setGeneric("show_graphic")
setMethod("show_graphic", "gComparativa", function(object){
})
I create and call the method with these code:
g <- new("gComparativa", data=data)
g.show_graphic()
But when I call the method I've this error:
Error in g.show_graphic() : This function cannot be found
"g.show_graphic"
What am I doing wrong? What can I define methods and call later?
r oop
r oop
asked Nov 13 '18 at 23:15
José CarlosJosé Carlos
69321946
69321946
1
Might be other issues and I'm not the most familiar with S4 but you don't call methods in R with dot notation like that, you just doshow_graphic(g)
. See more here adv-r.hadley.nz/s4.html#s4-generics
– Calum You
Nov 13 '18 at 23:25
1
@CalumYou Just saw your comment right after I posted my answer. I think technically your comment came first, so if you post as an answer I will delete.
– duckmayr
Nov 13 '18 at 23:27
add a comment |
1
Might be other issues and I'm not the most familiar with S4 but you don't call methods in R with dot notation like that, you just doshow_graphic(g)
. See more here adv-r.hadley.nz/s4.html#s4-generics
– Calum You
Nov 13 '18 at 23:25
1
@CalumYou Just saw your comment right after I posted my answer. I think technically your comment came first, so if you post as an answer I will delete.
– duckmayr
Nov 13 '18 at 23:27
1
1
Might be other issues and I'm not the most familiar with S4 but you don't call methods in R with dot notation like that, you just do
show_graphic(g)
. See more here adv-r.hadley.nz/s4.html#s4-generics– Calum You
Nov 13 '18 at 23:25
Might be other issues and I'm not the most familiar with S4 but you don't call methods in R with dot notation like that, you just do
show_graphic(g)
. See more here adv-r.hadley.nz/s4.html#s4-generics– Calum You
Nov 13 '18 at 23:25
1
1
@CalumYou Just saw your comment right after I posted my answer. I think technically your comment came first, so if you post as an answer I will delete.
– duckmayr
Nov 13 '18 at 23:27
@CalumYou Just saw your comment right after I posted my answer. I think technically your comment came first, so if you post as an answer I will delete.
– duckmayr
Nov 13 '18 at 23:27
add a comment |
1 Answer
1
active
oldest
votes
You'll need
show_graphic(g)
instead. R's OOP systems don't generally work like many other programming languages. (Here's a good primer).
You can't access class functions via <objectname>.<functionname>()
, but rather you just call the function on the object like <functionname>(<objectname>)
.
Consider that dots can be part of an object name in R; for example try
example.object <- 2
example.object
# [1] 2
add a comment |
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
});
}
});
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%2f53290907%2fr-object-doesnt-find-custom-function%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
You'll need
show_graphic(g)
instead. R's OOP systems don't generally work like many other programming languages. (Here's a good primer).
You can't access class functions via <objectname>.<functionname>()
, but rather you just call the function on the object like <functionname>(<objectname>)
.
Consider that dots can be part of an object name in R; for example try
example.object <- 2
example.object
# [1] 2
add a comment |
You'll need
show_graphic(g)
instead. R's OOP systems don't generally work like many other programming languages. (Here's a good primer).
You can't access class functions via <objectname>.<functionname>()
, but rather you just call the function on the object like <functionname>(<objectname>)
.
Consider that dots can be part of an object name in R; for example try
example.object <- 2
example.object
# [1] 2
add a comment |
You'll need
show_graphic(g)
instead. R's OOP systems don't generally work like many other programming languages. (Here's a good primer).
You can't access class functions via <objectname>.<functionname>()
, but rather you just call the function on the object like <functionname>(<objectname>)
.
Consider that dots can be part of an object name in R; for example try
example.object <- 2
example.object
# [1] 2
You'll need
show_graphic(g)
instead. R's OOP systems don't generally work like many other programming languages. (Here's a good primer).
You can't access class functions via <objectname>.<functionname>()
, but rather you just call the function on the object like <functionname>(<objectname>)
.
Consider that dots can be part of an object name in R; for example try
example.object <- 2
example.object
# [1] 2
answered Nov 13 '18 at 23:26
duckmayrduckmayr
7,29811226
7,29811226
add a comment |
add a comment |
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.
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%2f53290907%2fr-object-doesnt-find-custom-function%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
Might be other issues and I'm not the most familiar with S4 but you don't call methods in R with dot notation like that, you just do
show_graphic(g)
. See more here adv-r.hadley.nz/s4.html#s4-generics– Calum You
Nov 13 '18 at 23:25
1
@CalumYou Just saw your comment right after I posted my answer. I think technically your comment came first, so if you post as an answer I will delete.
– duckmayr
Nov 13 '18 at 23:27