Looking at internal Methods

后端 未结 2 1861
情深已故
情深已故 2020-12-14 11:24

I\'d like to be able to see the function that\'s used when I use str(), as I\'d like to modify it a bit for my own purposes as another function.

When I type s

相关标签:
2条回答
  • 2020-12-14 12:01

    You could also do it like this:

    > methods(by)
    [1] by.data.frame by.default
    > getS3method("by", "data.frame")
    function (data, INDICES, FUN, ..., simplify = TRUE) 
    {
       ...
    }
    <environment: namespace:base>
    
    0 讨论(0)
  • 2020-12-14 12:16

    You want methods() for an S3 generic such as str():

    > methods(str)
    [1] str.data.frame* str.Date*       str.default*   
    [4] str.dendrogram* str.logLik*     str.POSIXt*    
    
       Non-visible functions are asterisked
    

    Using getAnywhere(str) is not really helpful because str() is visible so you get the same result if you just run str at the prompt. You need getAnywhere() to look at the hidden methods listed above:

    getAnywhere(str.default)
    

    for example.

    Shame you need to know what kind of generic a function is to list the methods; seems user-friendliness would be improved if R didn't care what kind of method type was supplied to one or other of these functions.

    0 讨论(0)
提交回复
热议问题