[R] source code functions

Gavin Simpson gavin.simpson at ucl.ac.uk
Fri Jul 18 15:48:55 CEST 2008


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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list