[R] frequency() source code

Duncan Murdoch murdoch at stats.uwo.ca
Tue Nov 8 00:30:25 CET 2005


On 11/7/2005 6:11 PM, bob mccall wrote:
>   Greetings:
>  
>     I am looking for the source code for the frequency function. I 
>     grepped  the following dirs  but no luck. 
> 
>     R-2.2.0/src/appl/*
>     R-2.2.0/src/main/*
>     R-2.2.0/src/nmath/*
>     R-2.2.0/src/library/stats/*
> 
>     Does anybody know the file name??

Here's how I would look for it:

In R, type frequency, and I get:

 > frequency
function (x, ...)
UseMethod("frequency")
<environment: namespace:stats>

So frequency is a generic function.  That's all the source there is.

Now I'm probably interested in a particular method.  Let's say the 
default one.  So I try

 > frequency.default
Error: object "frequency.default" not found

Oops, looks like it's hidden in a namespace.  Try again:

 > getAnywhere("frequency.default")
A single object matching 'frequency.default' was found
It was found in the following places
   registered S3 method for frequency from namespace stats
   namespace:stats
with value

function (x, ...)
if (!is.null(xtsp <- attr(x, "tsp"))) xtsp[3] else 1
<environment: namespace:stats>

Now that's probably enough information, but if I really wanted to see 
the source (as opposed to the above deparsed version, which won't have 
any comments in it), then I'd know to look in src/library/stats/R, since 
it's in namespace:stats, and it's R code.  I'd grep or do another search 
of the files there and find it in src/library/stats/R/ts.R (and it turns 
out there aren't any comments after all, but it might be useful to look 
at the other functions in that file anyway).

Now if someone were running from a binary install in Windows, they 
wouldn't have a full copy of the source directories; they need to 
download that separately from the binary builds.

Duncan Murdoch




More information about the R-help mailing list