[R] Printing the function t.test() in R

David Winsemius dwinsemius at comcast.net
Wed Mar 31 14:45:51 CEST 2010


On Mar 31, 2010, at 8:35 AM, Luwis Tapiwa Diya wrote:

> Dear R Users,
>
> I have a question, how does one print an r function like t.test in R  
> (to get
> the whole function and not just a summary of the environment)?   For  
> example
> if I type the following:
>
>> t.test
> function (x, ...)
> UseMethod("t.test")
> <environment: namespace:stats>
>> print(t.test)
> function (x, ...)
> UseMethod("t.test")
> <environment: namespace:stats>
>
> I don't get the entire function printed.

 > methods(t.test)
[1] t.test.default* t.test.formula*

    Non-visible functions are asterisked
# Noting the asterisk, one need to use getAnywhere()

 > getAnywhere(t.test.default)
A single object matching ‘t.test.default’ was found
It was found in the following places
   registered S3 method for t.test from namespace stats
   namespace:stats
with value

function (x, y = NULL, alternative = c("two.sided", "less", "greater"),
     mu = 0, paired = FALSE, var.equal = FALSE, conf.level = 0.95,
     ...)
### snipped the code -----------------

There was an R-News a couple of years back by (if memory serves)  
Ligges describing various methods for getting at source. Yes, there it  
is:
Ligges, U. (2006): R Help Desk: Accessing the Sources. R News 6 (4),   
43-45. http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list