[R] looking at a function's code

2007-07-16 Thread Walter Paczkowski
Good morning,

I'd like to look at the code for the R function head.  When I type just the 
word head, I get back

function(x, ...)
UseMethod(head)
environment: namespace:utils


I expected to see several lines of R code.  Any suggestions?

Thanks,

Walt Paczkowski

__
R-help@stat.math.ethz.ch 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.


Re: [R] looking at a function's code

2007-07-16 Thread Duncan Murdoch
On 16/07/2007 8:02 AM, Walter Paczkowski wrote:
 Good morning,
 
 I'd like to look at the code for the R function head.  When I type just the 
 word head, I get back
 
 function(x, ...)
 UseMethod(head)
 environment: namespace:utils
 
 
 I expected to see several lines of R code.  Any suggestions?

Even though it's not very informative, that really is the source for 
that function.  For instructions on how to see the more useful stuff, 
see Uwe Ligges' article in the Oct 2006 R News (available at 
http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf).

Duncan Murdoch

__
R-help@stat.math.ethz.ch 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.


Re: [R] looking at a function's code

2007-07-16 Thread Chuck Cleland
Walter Paczkowski wrote:
 Good morning,
 
 I'd like to look at the code for the R function head.  When I type just the 
 word head, I get back
 
 function(x, ...)
 UseMethod(head)
 environment: namespace:utils
 
 
 I expected to see several lines of R code.  Any suggestions?

  Have a look at:

https://svn.r-project.org/R/trunk/src/library/utils/R/head.R

  Also, ?head shows methods for different types of objects, and you can
see these with

getAnywhere(head.default)

or

utils:::head.default

 Thanks,
 
 Walt Paczkowski
 
 __
 R-help@stat.math.ethz.ch 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@stat.math.ethz.ch 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.


Re: [R] looking at a function's code

2007-07-16 Thread Karl Ove Hufthammer
Walter Paczkowski:

 I'd like to look at the code for the R function head.  When I type just
 the word head, I get back
 
 function(x, ...)
 UseMethod(head)
 environment: namespace:utils

This basically means that 'head' is a generic function that works in
different ways for different classes of objects (data frames, matrices,
tables c.) Many function, e.g., 'plot' and 'mean', work the same way.

Type ?UseMethod for a better/longer explanation.

Now type

methods(head)

You will get:

[1] head.data.frame* head.default*head.ftable* head.function*
[5] head.matrix  head.table*

Now, ordinarily you should be able to write 'head.data.frame' to see the
code for this function, but, since it is starred, '*', this doesn't work.
The easiest way to get hold of it is using 'getAnywhere':

getAnywhere(head.data.frame)

-- 
Karl Ove Hufthammer

__
R-help@stat.math.ethz.ch 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.