Hello.
I'm trying to write a function to do a particular job (in my case, analyse a data set for outliers) so the first things I want to do is look at how other people have done similar jobs.
I can do this to load a particular package and examine the code of a function, but some functions seem to depend on what class of object you throw at it
>library(outliers)
> fix(outlier)
function (x, opposite = FALSE, logical = FALSE)
{
if (is.matrix(x))
apply(x, 2, outlier, opposite = opposite, logical = logical)
else if (is.data.frame(x))
sapply(x, outlier, opposite = opposite, logical = logical)
else {
if (xor(((max(x) - mean(x)) < (mean(x) - min(x))), opposite)) {
if (!logical)
min(x)
else x == min(x)
}
else {
if (!logical)
max(x)
else x == max(x)
}
}
}
How can you look at the code of something that changes depending on the object ?
Edit:
OK, Palm <- face. The function I used as an example just calls itself, but allt he code is there... I have seen other examples (but can't think of any offhand) where the function did do other things depending on the class of the object thrown at it, so the question stands, even though it's a bad example !