R: Object doesn't find custom function










1















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?










share|improve this question

















  • 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















1















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?










share|improve this question

















  • 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













1












1








1








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 23:15









José CarlosJosé Carlos

69821946




69821946







  • 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












  • 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







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












1 Answer
1






active

oldest

votes


















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





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%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









    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





    share|improve this answer



























      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





      share|improve this answer

























        2












        2








        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





        share|improve this answer













        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 23:26









        duckmayrduckmayr

        7,30811326




        7,30811326



























            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto