How to find all functions in an R package?

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")

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.

Tags:

R

R Faq