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?
-
no problem, but there was no need to delete the question. I could provide the answer, and it could help others in future who encounter the same issue as yours. – Marcin Jul 06 '21 at 00:58
6 Answers
You can get all the objects in your package with:
ls("package:caTools")
You can get all the function signatures in your package with:
lsf.str("package:caTools")

- 43,891
- 12
- 98
- 133
-
You may have some function names starting wit . , so ls(xxxx, all=TRUE) guarantees that all exported functions are listed. And you can examine source code for functions that are not exported i.e. not really meant for end user but used in a package internally (but that are still sometimes useful - and used - by others). – lebatsnok Dec 12 '13 at 05:26
-
3Just a comment: the package should be attached before you can list its objects or functions. – mt1022 Apr 23 '18 at 14:17
-
1To output just the function names, you can apply as.character to lsf.str – Tripartio Sep 30 '22 at 21:53
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.
-
1I like this answer because it does not require to install an extra package. Only stuff from the base. Cool! – Andry Apr 11 '20 at 08:42
-
Note that `ls(..., all.names = T)` may return more names (starting with a dot). Moreover, `getNamespaceExports("stringr")` is not exactly a subset of `ls(getNamespace("stringr"))`, as it also exports `%>%` from magrittr. In general both `setdiff` are interesting. – Mar 23 '22 at 15:41
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:
x <- library(help = caTools)
x$info[[2]]
# [1] "LogitBoost LogitBoost Classification Algorithm"
# [2] "base64encode Convert R vectors to/from the Base64 format"
# [3] "caTools-package Tools: moving window statistics, GIF, Base64,"
# [4] " ROC AUC, etc."
# [5] "colAUC Column-wise Area Under ROC Curve (AUC)"
# [6] "combs All Combinations of k Elements from Vector v"
# [7] "predict.LogitBoost Prediction Based on LogitBoost Classification"
# [8] " Algorithm"
# [9] "read.ENVI Read and Write Binary Data in ENVI Format"
# [10] "read.gif Read and Write Images in GIF format"
# [11] "runmad Median Absolute Deviation of Moving Windows"
# [12] "runmean Mean of a Moving Window"
# [13] "runmin Minimum and Maximum of Moving Windows"
# [14] "runquantile Quantile of Moving Window"
# [15] "runsd Standard Deviation of Moving Windows"
# [16] "sample.split Split Data into Test and Train Set"
# [17] "sumexact Basic Sum Operations without Round-off Errors"
# [18] "trapz Trapezoid Rule Numerical Integration"

- 190,393
- 28
- 405
- 485
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

- 108,132
- 65
- 322
- 519
Just figured that if you just go to Environment tab -> click Global Environment -> click the package you want to see (I selected dplyr
here for demonstration but in your case it will be caTools
), all functions, values and data will be displayed.

- 121
- 1
- 2
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

- 41,291
- 27
- 223
- 311
-
Maybe this link should be in the posted answer: ["collidr: Check for Namespace Collisions Across Packages and Functions on CRAN"](https://cran.r-project.org/web/packages/collidr/index.html). – Anton Antonov Sep 27 '21 at 12:17