Re: [R] Probing a function

From: Henrik Bengtsson <hb_at_biostat.ucsf.edu>
Date: Mon, 28 Mar 2011 21:00:01 -0700

Hi.

On Mon, Mar 28, 2011 at 8:40 PM, Dennis Fisher <fisher_at_plessthan.com> wrote:
> R 2.12.2
> Windows 7
>
> Colleagues,
>
> I just took advantage of the function:
>        readWindowsShortcut
> in R.utils.  It accomplished my goals and I was interested in learning its inner workings.  So, I typed the function at the command line (without arguments or parentheses).  R returned:
>
>        function (...)
>        UseMethod("readWindowsShortcut")
>        <environment: namespace:R.utils>
>
> providing no insight to me as to the commands in the function.

That "UseMethod(...)" says that the method is a so called "S3 generic function", cf. help("UseMethod"). Simply speaking, when a generic function is called, it looks at the arguments sent to it and from those decides which "specialized method" of the same name should be called. To find out which "specialized methods" are available for a generic function, do:

> methods("readWindowsShortcut")

[1] readWindowsShortcut.default

So, in this particular case, there is only one method. Also, whenever you see a method named <generic function>.default, it means that that method is the fallback method, which will be called if the generic function finds no better options. All what I said, is an extremely brief version of how (S3) method dispatch works.

>
> So, how do I (or, can I) access the code in that function?

>From the above, the source code you are interested in can be found by:

> print(readWindowsShortcut.default)

/Henrik

>
> Thanks in advance
>
> Dennis
>
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> ______________________________________________
> 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.
>



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. Received on Tue 29 Mar 2011 - 04:02:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Mar 2011 - 04:10:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive