how to view source code of a function inside a package?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

how to view source code of a function inside a package?

tmrsg11
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>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to view source code of a function inside a package?

Duncan Murdoch-2
On 15/11/2012 2:21 PM, C W 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?

You can use the prefix MCMC:::foo to display the foo function from MCMC,
whether or not it is exported.

Duncan Murdoch

>
> 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>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to view source code of a function inside a package?

Sarah Goslee
In reply to this post by tmrsg11
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 <[hidden email]> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to view source code of a function inside a package?

tmrsg11
In reply to this post by Duncan Murdoch-2
thanks all.  The mcmc:::foo is exactly what I am looking for.

On Thu, Nov 15, 2012 at 2:35 PM, Duncan Murdoch <[hidden email]>wrote:

> On 15/11/2012 2:21 PM, C W 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?
>>
>
> You can use the prefix MCMC:::foo to display the foo function from MCMC,
> whether or not it is exported.
>
> Duncan Murdoch
>
>
>> 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>
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________**________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to view source code of a function inside a package?

Suzen, Mehmet-2
In reply to this post by tmrsg11
It might be a C code wrapped around.
-m

On Thu, Nov 15, 2012 at 8:21 PM, C W <[hidden email]> 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>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Mehmet Süzen, Ph.D. ( Dr.phil.nat. )
<[hidden email]>

| PRIVILEGED AND CONFIDENTIAL COMMUNICATION This e-mail transmission,
and any documents, files or previous e-mail messages attached to it,
may contain confidential information that is legally privileged. If
you are not the intended recipient or a person responsible for
delivering it to the intended recipient, you are hereby notified that
any disclosure, copying, distribution or use of any of the information
contained in or attached to this transmission is STRICTLY PROHIBITED
within the applicable law. If you have received this transmission in
error, please: (1) immediately notify me by reply e-mail to
[hidden email],  and (2) destroy the original transmission and its
attachments without reading or saving in any manner. |

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.