34

I know ls("package:grid") and find.funs("package:grid") in mvbutils but apparently neither of them can find non-exported functions and methods that are only accessible internally or with ::: or getAnywhere.

I've had to source the files in the /R directory of the source package and use ls() on a clean global environment, but there must be a better way, no?

baptiste
  • 75,767
  • 19
  • 198
  • 294
  • ``get`` and ``getFromNamespace`` seem to call to an ``.internal``, and they need to know a particular name, which doesn't help much. That your read? – Gregg Lind Jan 01 '12 at 23:14
  • What is a particular symbol in ``package:grid`` that you don't see listed in ``ls(package:grid)`` but expect to? – Gregg Lind Jan 01 '12 at 23:18
  • 481 of them, according to the solutions below `setdiff(unclass(lsf.str(envir = asNamespace("grid"), all = T)), ls('package:grid'))` – baptiste Jan 02 '12 at 00:30

2 Answers2

34

you can use asNamespace:

> methods(cbind)
[1] cbind.data.frame cbind.grobGrid   cbind.ts*       

   Non-visible functions are asterisked
> r <- unclass(lsf.str(envir = asNamespace("stats"), all = T))
> r[grep("cbind.ts", r)]
[1] ".cbind.ts" "cbind.ts" 

cbind.ts in stats package is invisible but can find in envir = asNamespace("stats").

kohske
  • 65,572
  • 8
  • 165
  • 155
27

This appears to be something of a perennial here.

If it's this one-liners you're after then this should be a contender (credit @Joshua):

ls(getNamespace("grid"), all.names=TRUE)

(Link is to a question that was asked after the above, but closely related).

As grid is a base package and I haven't yet moved up to R 3... I'm getting 756 functions with Version 2.15.1. vs. 503 from the unclass solution.

Community
  • 1
  • 1
dardisco
  • 5,086
  • 2
  • 39
  • 54
  • 1
    `707` vs `778` in recent R; most of the setdiff seems to be internal C routines (`grid:::L_textBounds`) or constants (`grid:::Mb`). – baptiste Jun 25 '13 at 11:12
  • 1
    Thanks. To have only private functions : `setdiff( ls(getNamespace("ThePackage"), all.names=TRUE), ls("package:ThePackage", all.names=TRUE))` – phili_b Jul 27 '22 at 14:31