[R] expressing functions

Gabor Grothendieck ggrothendieck at myway.com
Wed Dec 10 06:04:34 CET 2003



Perhaps what should be added to the previous answers is
that you can find out where the real work is done like
this:

require(ctest)
t.test
methods(t.test)
ctest:::t.test.default
ctest:::t.test.formula

If the class of the first argument to t.test is formula
then t.test.formula gets invoked so that's where the
real work is done; otherwise, t.test.default
gets invoked so that's where the real work is done.

--- 
 
Remington, Richard wrote:
> # Why does expressing one function
> 
> require(ctest)
> t.test
> 
> # return only
> 
> function (x, ...)
> UseMethod("t.test")
> <environment: namespace:ctest>
> 
> # but expressing another function
> 
> shapiro.test
> 
> # returns more complete code?
> 
> function (x)
> {
> DNAME <- deparse(substitute(x))
> x <- sort(x[complete.cases(x)])
> n <- length(x)
> if (n < 3 || n > 5000)
> stop("sample size must be between 3 and 5000")




More information about the R-help mailing list