[R] replacing functions

Dieter Menne dieter.menne at menne-biomed.de
Mon Sep 6 15:15:18 CEST 2010



Karen Sargsyan wrote:
> 
> Is it possible to replace function with my own? I want to apply pca 
> clustering, but to use some strange correlation function. I'm asking about
> replacing,  say, mean() with new content of mean() and use standard other
> functions,  which might use mean() as part.
> 

The usual way would be to get the source code for the function you are
trying to change (or, fast way, with getAnywhere(pca)), copy it to an
editor, and make the changes. However, better always rename it before using,
e.g. pcaKaren <- function....

If the code you are trying to change is not directly called, but indirectly,
things are more complicated. In most cases, it's easiest to get the whole
package, put it into a different namespace, and make the changes. Easiest
does not mean not easy, though.

Dieter


-- 
View this message in context: http://r.789695.n4.nabble.com/replacing-functions-tp2528143p2528361.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list