[R] how to view source code of a function inside a package?

Sarah Goslee sarah.goslee at gmail.com
Thu Nov 15 20:40:39 CET 2012


This is R FAQ 7.40, and that document gives some good pointers:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-access-the-source-code-for-a-function_003f

I prefer to simply download the source code version of the package
from CRAN, so that comments aren't stripped, but there are several
other options.

Sarah

On Thu, Nov 15, 2012 at 2:21 PM, C W <tmrsg11 at gmail.com> wrote:
> Dear list,
> I am trying to look at the function inside a package.  I know that
> methods() would do the trick, but what if the function is hidden?  I have a
> problem displaying the hidden function.
>
> Say, for example the MCMC package.  How do you view the code of that
> function?
>
> something like this:
>
>> which
>
> function (x, arr.ind = FALSE, useNames = TRUE)
>
> {
>
>     wh <- .Internal(which(x))
>
>     if (arr.ind && !is.null(d <- dim(x)))
>
>         arrayInd(wh, d, dimnames(x), useNames = useNames)
>
>     else wh
>
> }
>
> <bytecode: 0x1021eef50>
>
> <environment: namespace:base>


--
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list