Re: [R] source code functions

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Fri, 18 Jul 2008 14:48:55 +0100

On Fri, 2008-07-18 at 09:37 -0400, stephen sefick wrote:
> >na.contiguous
> function (object, ...)
> UseMethod("na.contiguous")
> <environment: namespace:stats>
>
> this is what I get when I look for the source code for some functions- Is
> there a way to look at the source code?

na.contiguous is an S3 generic function, and that *is* the source for it! To see what methods are available, used methods():

> methods(na.contiguous)
[1] na.contiguous.default*

   Non-visible functions are asterisked

To see the code in the available method, you need to access it in the relevant namespace as it is hidden from the user:

> na.contiguous.default

Error: object "na.contiguous.default" not found
> getAnywhere(na.contiguous.default)

A single object matching ‘na.contiguous.default’ was found It was found in the following places
  registered S3 method for na.contiguous from namespace stats   namespace:stats
with value

function (object, ...)
{
...snip...

?UseMethod would have got you there.

See Uwe Ligges RNews article on this very subject:

http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf

HTH G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
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 Fri 18 Jul 2008 - 14:26:46 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 Fri 18 Jul 2008 - 15:02:01 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