I would like to know what the formula for a particular function is. Usually when I type the function without the parentheses, it returns a formula, so if I type sd I will get:
function (x, na.rm = FALSE)
{
if (is.matrix(x))
apply(x, 2, sd, na.rm = na.rm)
else if (is.vector(x))
sqrt(var(x, na.rm = na.rm))
else if (is.data.frame(x))
sapply(x, sd, na.rm = na.rm)
else sqrt(var(as.vector(x), na.rm = na.rm))
}
<environment: namespace:stats>
Which is fine. But if I were to type rollmean with the zoo package loaded it returns this:
function (x, k, fill = if (na.pad) NA, na.pad = FALSE, align = c("center",
"left", "right"), ...)
{
UseMethod("rollmean")
}
<environment: namespace:zoo>
I am guessing something is going on in the method rollmean, but how do I get to see what is going on in there? This may be a novice question but I am having a hard time finding out how to see the underlying formula of a particular function.
Two options :
1) Using the method mechanism, as Nick Sabbe suggests. Notice it is quite hasardous, as it depends greatly on how the class, generic and methods were implemented and in which Object-Oriented framework its was (S3, S4, R5).
2) Looking for the R source directly. As it is a package, it is quite easy : find the .tar.gz version of the package, look for the ‘R’ directory and you will find the source code (with the developper’s comments, if any). For zoo : http://cran.r-project.org/src/contrib/zoo_1.7-6.tar.gz