0

I'm wondering how I can access the source code for function bayesmeta in the bayesmeta package. Seeing similar questions, I have tried using package:::function, using getAnywhere and methods("bayesmeta") with no success.

Is there a better way to access the source code from within R in this case?

library("bayesmeta")

bayesmeta:::bayesmeta

getAnywhere("bayesmeta")

methods("bayesmeta")
rnorouzian
  • 7,397
  • 5
  • 27
  • 72
  • Have you tried all the methods listed [here](https://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function?answertab=votes#tab-top) ? – Tim Biegeleisen Dec 31 '17 at 03:28
  • @TimBiegeleisen, you mean `methods("bayesmeta")`? If yes, unfortunately that didnot work. – rnorouzian Dec 31 '17 at 03:30
  • What about `getMethod("bayesmeta", "bayesmeta")` ? – Tim Biegeleisen Dec 31 '17 at 03:31
  • @TimBiegeleisen, that gives the following error: `Error in getMethod("bayesmeta", "bayesmeta") : no generic function found for 'bayesmeta'` – rnorouzian Dec 31 '17 at 03:32
  • 1
    My favorite way of browsing the source code is through GitHub. https://github.com/cran/bayesmeta My search term for it through your favorite browser is "cran github bayesmeta". – Roman Luštrik Dec 31 '17 at 07:51

1 Answers1

1

In case of doubt, I like to look at the actual source code. You can download the package source from CRAN and look directly at the source file in the R directory.

The package is available here: https://cran.r-project.org/web/packages/bayesmeta/index.html (see the "Package source" line).

Direct link to the source: https://cran.r-project.org/src/contrib/bayesmeta_2.0.tar.gz

I prefer to look at the original package source because then I see comments, functions I may not know exist, functions that are not exported, etc.

In this case, from the package source, you can see that the main function is called bayesmeta.default:

> bayesmeta:::bayesmeta.default
function (y, sigma, labels = names(y), tau.prior = "uniform", 
    mu.prior = c(mean = NA, sd = NA), mu.prior.mean = mu.prior[1], 
    mu.prior.sd = mu.prior[2], interval.type = c("shortest", 
        "central"), delta = 0.01, epsilon = 1e-04, rel.tol.integrate = 2^16 * 
        .Machine$double.eps, abs.tol.integrate = rel.tol.integrate, 
    tol.uniroot = rel.tol.integrate, ...) 
{
    ptm <- proc.time()
    y <- as.vector(y)
    sigma <- as.vector(sigma)
    labels <- as.vector(labels)
    stopifnot(is.vector(y), is.vector(sigma), all(is.finite(y)), 
        all(is.finite(sigma)), length(sigma) == length(y), all(sigma >= 
            0), sum(sigma == 0) <= 1, length(mu.prior) == 2, 
        length(mu.prior.mean) == 1, length(mu.prior.sd) == 1, 
        is.na(mu.prior.mean) || is.finite(mu.prior.mean), is.na(mu.prior.sd) || 
            (is.finite(mu.prior.mean) && (mu.prior.sd > 0)), 
        ((is.na(mu.prior.mean) & is.na(mu.prior.sd)) || (is.finite(mu.prior.mean) & 
            is.finite(mu.prior.sd))), (is.function(tau.prior) | 
            (is.character(tau.prior) && (length(tau.prior) == 
                1))))
     etc. ...
Claus Wilke
  • 16,992
  • 7
  • 53
  • 104