What is the best way to find all the functions associated in a package?? I am currently going through the caTools package. If I do ?caTools
or ??caTools
I am simply going to get search for functions called that but not the functions in the package. Is there an easy way to access all the functions in the R gui? Are there any good ways to search for functions?
How to find all functions in an R package?
6.9k views Asked by jessica At
6
There are 6 answers
0
On
The pacman
package (CRAN) (Dev Version: GitHub) works well for this. Specifically the p_funs
function.
The syntax is:
p_funs(caTools) # exported
p_funs(caTools, TRUE) # includes non-exported
3
On
If you want all exported functions (i.e. functions accessible via ::
), then getNamespaceExports(pkgName)
will do the trick.
If you want all functions in the package, including the ones accessible via :::
, you can do ls(getNamespace(pkgName))
.
As an example, with the stringr
package:
getNamespaceExports("stringr")
[1] "fixed" "ignore.case" "invert_match" "perl" "str_c" "str_count" "str_detect" "str_dup" "str_extract"
[10] "str_extract_all" "str_join" "str_length" "str_locate" "str_locate_all" "str_match" "str_match_all" "str_pad" "str_replace"
[19] "str_replace_all" "str_split" "str_split_fixed" "str_sub" "str_sub<-" "str_trim" "str_wrap" "word"
However, we know that stringr:::is.perl
exists in the package, and as you can see:
setdiff(ls(getNamespace("stringr")), getNamespaceExports("stringr"))
[1] "case.ignored" "check_pattern" "check_string" "compact" "is.fixed" "is.perl" "match_to_matrix" "re_call" "recyclable"
[10] "re_mapply"
So, we see that ls(getNamespace("stringr"))
contains all of getNamespaceExports("stringr")
in addition to the :::
functions.
1
On
Another way is to use collidr
package
library(collidr)
library(dplyr)
collidr::CRANdf %>%
filter(package_names == "caTools")
# package_names function_names
# 1 caTools caTools-package
# 2 caTools base64encode
# 3 caTools base64decode
# 4 caTools colAUC
# 5 caTools combs
# 6 caTools LogitBoost
# 7 caTools predict.LogitBoost
# 8 caTools read.ENVI
# 9 caTools write.ENVI
# 10 caTools read.gif
# 11 caTools write.gif
# 12 caTools runmad
# 13 caTools runmean
# 14 caTools runmin
# 15 caTools runmax
# 16 caTools runquantile
# 17 caTools runsd
# 18 caTools sample.split
# 19 caTools sumexact,
# 20 caTools cumsumexact
# 21 caTools trapz
I am guessing that you are just looking for
help(package = caTools)
, which will open your browser to the relevant help page that lists all the functions in the "caTools" package.You can also try:
library(help = caTools)
, but that doesn't seem to capture everything. The nice thing about this latter approach is that you can capture the output in case you needed to refer to it somewhere else: