6

New to the forum. Is there a way to search for functions within a particular library in R?

Lets say I would like a list of all the functions in the "graphics" library. How would do that?

If I want to find the specific documentation on the "plot" command I am having trouble finding the documentation when I used the help.search("plot"). It gives me all these other functions from different libraries. I just want to be able to find and narrow down the searches when I look for a particular function.

John Conde
  • 217,595
  • 99
  • 455
  • 496
alphabeta
  • 687
  • 1
  • 6
  • 7
  • For finding methods for a generic function such as `plot`, read http://stackoverflow.com/questions/8691812/get-object-methods-r – mnel Oct 05 '12 at 02:44
  • You might find an earlier answer of mine helpful: http://stackoverflow.com/questions/12575098/to-see-all-the-content-not-just-objects-in-a-package-in-r/12576217#12576217 – Maiasaura Oct 05 '12 at 03:38

4 Answers4

7

For a listing of all the functions within a package, and links to their documentations, do:

help(package = "graphics")

That of course assumes that you have installed the package.


For your other question:

If you already know the name of the function you are looking for, do not use help.search("plot") but help("plot"). As the name suggests, help.search does a search through all the docs and returns every hit, very much like a Google search.

Finally, know that you can use:

  • ?plot as a shortcut to help("plot")
  • ??plot as a shortcut to help.search("plot").
flodel
  • 87,577
  • 21
  • 185
  • 223
4

Here's an example with the package graphics:

library(graphics)   #first load the package 
OBJS <- objects("package:graphics")    #use objects to look at all objects
DS <- data(package="graphics")[["results"]][, "Item"]   #find the data sets
OBJS[!OBJS %in% DS]  #compare to data sets

Here it is wrapped up as function:

funs <- function(package) {
    pack <- as.character(substitute(package))[1]
    require(pack, character.only = TRUE)
    OBJS <- objects(paste0("package:", pack)) 
    DS <- data(package=pack)[["results"]][, "Item"]  
    OBJS[!OBJS %in% DS]  
}

funs(graphics)
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
3

An answer from Brian Ripley on R-help

ls("package:ts")

will list all the objects in the package (I presume package and not library was meant: a library is a directory holding installed packages).

If you really want to know about the functions (and not all objects) in a package try

lsf.str("package:ts")

which gives the call sequences too.


unknownR

I will also spruik the unknownR package. There is a nice demonstration here.

It is a tool to go search through functions top packages (helps you learn your unknown unknowns)

mnel
  • 113,303
  • 27
  • 265
  • 254
0

If you are looking for a function in package foo, sometimes ??foo works quite good.

Ali
  • 9,440
  • 12
  • 62
  • 92