How to Get the Function Code in R

http://fhqdddddd.blog.163.com/blog/static/1869915420104111031148/

 

http://blog.sina.com.cn/s/blog_61f013b80100gekp.html

http://rbbs.biosino.org/Rbbs/posts/list/1073.page

 

 

How to Get the Function Code in R

R is “open-access”, so I can read and modify the function code for further application. And that is the reason I choose it, use it and love it.

 

But first, let’s explore how to get the function code.

1. On R Console. function_name + Enter. For example:

> fivenum

function (x, na.rm = TRUE)

{

    xna <- is.na(x)

    if (na.rm)

        x <- x[!xna]

    else if (any(xna))

        return(rep.int(NA, 5))

    x <- sort(x)

    n <- length(x)

    if (n == 0)

        rep.int(NA, 5)

    else {

        n4 <- floor((n + 3)/2)/2

        d <- c(1, n4, (n + 1)/2, n + 1 - n4, n)

        0.5 * (x[floor(d)] + x[ceiling(d)])

    }

}

<environment: namespace:stats>

2. function_name.default. For example:

>qqnorm.default

# this is a visible function, a special case of 3 later.

3. For generic functions like “rep”

>t.test

function (x, ...)

UseMethod("t.test")

<environment: namespace:stats>

 

>methods(“t.test”)

 [1] t.test.default* t.test.formula*

   Non-visible functions are asterisked

# first, we should known the “methods” used.

 

>getAnywhere(“t.test.default”)  or >stats:::t.test.default or >getS3method(“t.test”,“default”)

# get “t.test.default” code

4.  If all the methods discussed above cannot help, just open the R-code(.tar.gz) for the Z-plan.

 

 

For more:

http://cran.csdb.cn/

http://rbbs.biosino.org/Rbbs/posts/list/63.page#574#574

http://www.pinggu.org/bbs/b69i336419.html

http://cos.name/bbs/read.php?tid=1065

http://tel.pinggu.org/bbs/b69i456670p4.html

 

In addition, thanks for Dr. Ding’s prompt help and discussion about the “wilcox.test” function code in R.

posted @ 2016-04-30 21:39  junjunang  阅读(287)  评论(0编辑  收藏  举报