The name of the package for the given function in R

Possible duplicate:
How do you define a function namespace?

I don’t know how to do this ... How do you know the package name for a specific function in R? I would like to have a function that sets the name of the function, returns the name of the package to which it belongs. Any suggestion?

+6
source share
1 answer

There may be better solutions, but find("functionname") seems to work quite well? However, it only works for downloaded packages.

 > find("strwidth") [1] "package:graphics" > find("qplot") character(0) > library(ggplot2) > find("qplot") [1] "package:ggplot2" > 

(If you need a raw package name, you can use gsub("^package:","",results) )

(The answer to the previous question related to Andrie includes this answer: they don't give a bit about gsub , and they all seem to be unable to find unsupported packages.)

Here you can quickly find functions even in unloaded packages:

 findAllFun <- function(f) { h <- help.search(paste0("^",f,"$"),agrep=FALSE) h$matches[,"Package"] } findAllFun("qplot") ## "ggplot2" findAllFun("lambertW") ## "emdbook" "VGAM" > findAllFun("xYplot") ## "Hmisc" "lattice" 

If you need to find functions in non-installed packages (i.e. CRAN search) then findFn from sos package will be your friend.

+6
source

Source: https://habr.com/ru/post/915509/


All Articles