zhiwei li
zhiwei li

Reputation: 1711

How to view the source code of functions that are not exported in the R package

I am following this tutorial and would like to use and view the source code of a function that is not exported. But it failed.

The name of this unexported function is diag(), which exists in the coxme package.

When I type coxme::diag() in Console, I can find that the function diag() does exist.

> coxme::diag()
Error: 'diag' is not an exported object from 'namespace:coxme'

But when I type coxme:::diag(), I can't find this function. I don't know why. In this tutorial, the author successfully to find the function by typing usethis:::base_and_recommended().

> coxme:::diag
Error: object 'diag' not found

Upvotes: 1

Views: 385

Answers (1)

Nir Graham
Nir Graham

Reputation: 5137

library(coxme)
getAnywhere(diag)
getAnywhere(diag)[1]
showMethods(diag)
differing objects matching ‘diag’ were found
in the following places
  package:bdsmatrix
  package:base
  namespace:base
  namespace:Matrix
  namespace:bdsmatrix
Use [] to view one of them

standardGeneric for "diag" defined from package "base"

function (x = 1, nrow, ncol, names = TRUE) 
standardGeneric("diag")
<environment: 0x0000014df6d2a480>
Methods may be defined for arguments: x, nrow, ncol, names
Use  showMethods(diag)  for currently available ones.

Function: diag (package base)
x="ANY"
x="bdsmatrix"
x="CsparseMatrix"
x="diagonalMatrix"
x="gchol"
x="gchol.bdsmatrix"
x="indMatrix"
x="packedMatrix"
x="RsparseMatrix"
x="TsparseMatrix"
x="unpackedMatrix"

Upvotes: 2

Related Questions