[R] Probing a function

Henrik Bengtsson hb at biostat.ucsf.edu
Tue Mar 29 06:00:01 CEST 2011


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



More information about the R-help mailing list