[R] How to see the implementation of print function for a class from a package?

R. Michael Weylandt michael.weylandt at gmail.com
Sun Jun 10 16:09:44 CEST 2012


Perhaps it's an S4 object? You can test that with isS4() and, if it is, try

showMethods("show")

showMethods(class = "datation")

getMethod("show", "datation")

Note that it's also entirely possible that your object doesn't have a
print method and instead falls back on print.default or some other
inherited method, though that doesn't seem to be the case here. E.g.,

x <- 1:5
class(x) <- "flub"

print(x) # Uses print.default b/c there's no print.flub

It would be helpful if you could say where the package is from so the
rest of us could look at it and help you more effectively.

Michael

On Sun, Jun 10, 2012 at 12:49 AM, Majid Einian <einian85 at gmail.com> wrote:
> I am working on the package "datation" and it is not on CRAN.
>
> On Sun, Jun 10, 2012 at 8:28 AM, R. Michael Weylandt
> <michael.weylandt at gmail.com> wrote:
>>
>> I presume your problem is that you are looking for non-exported
>> methods in some unstated package.
>>
>> Generally the pattern is something like this
>>
>> methods(plot) # shows all plot.* methods
>>
>> methods(class = "lm") # shows all *.lm methods
>
>
>> methods(class="datation")
>
> [1] summary.datation
>
>
>  so there I can see only summary. but I know that there should be a print
> function too:
>
>> CEPR
> Datation name : CEPR Business Cycle Dating Committee
>    Peaks Troughs Duration
> 1 1974Q3  1975Q1        2
> 2 1980Q1  1982Q3       10
> 3 1992Q1  1993Q3        6
>> class(CEPR)
> [1] "datation"
> attr(,"package")
> [1] "datation"
>
>
>
>
>> Those marked with a star are not exported but you can get at them with
>> the getAnywhere() function [you can also use three colons instead of
>> two, but that requires you to know the function at hand]
>
>
> getAnywhere shows me that there are methods for plot in this package, but I
> cannot see the implementation e.g. plot.datation
>
>
>
>>
>> Incidentally, you might also want to download the package source from
>> CRAN and browse it to see the author's commented code.
>
> Well, the package is not on CRAN, and the author has not answered my last
> email!
>
>>
>> Michael
>>
>> On Sat, Jun 9, 2012 at 10:53 PM, Majid Einian <einian85 at gmail.com> wrote:
>> > Dear R-helpers,
>> > I want to see the code used when printing (using print(object) or by
>> > just
>> > typing the object name) for a class from a package.
>> > I can see the summary code using packagename::summary.classname but
>> > nothing
>> > for print method and also plot methods.
>> >
>> > In general, how can I see the COMPLETE code for a package? not just the
>> > function defs?
>> >
>> > --
>> > Majid Einian,
>> > PhD Candidate in "Economics",
>> > Graduate School of Management and Economics,
>> > Sharif University of Technology,
>> > Tehran, IRAN
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> --
> Majid Einian,
> PhD Candidate in "Economics",
> Graduate School of Management and Economics,
> Sharif University of Technology,
> Tehran, IRAN
>



More information about the R-help mailing list