Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何查找R包中的所有函数?_R_R Faq - Fatal编程技术网

如何查找R包中的所有函数?

如何查找R包中的所有函数?,r,r-faq,R,R Faq,查找包中所有相关函数的最佳方法是什么??我目前正在浏览caTools软件包。如果我使用?caTools或?caTools,我只需要搜索调用它的函数,而不是包中的函数。有没有一种简单的方法可以访问R gui中的所有功能?有什么好方法可以搜索函数吗?您可以使用以下工具获取软件包中的所有对象: ls("package:caTools") lsf.str("package:caTools") 您可以通过以下方式获得软件包中的所有函数签名: ls("package:caTools") lsf.str

查找包中所有相关函数的最佳方法是什么??我目前正在浏览caTools软件包。如果我使用
?caTools
?caTools
,我只需要搜索调用它的函数,而不是包中的函数。有没有一种简单的方法可以访问R gui中的所有功能?有什么好方法可以搜索函数吗?

您可以使用以下工具获取软件包中的所有对象:

ls("package:caTools")
lsf.str("package:caTools")
您可以通过以下方式获得软件包中的所有函数签名:

ls("package:caTools")
lsf.str("package:caTools")

我猜您只是在寻找
帮助(package=caTools)
,它将打开浏览器到相关的帮助页面,该页面列出了“caTools”包中的所有功能

您也可以尝试:
库(help=caTools)
,但这似乎并不能捕获所有内容。后一种方法的优点是,您可以捕获输出,以防需要在其他地方引用它:

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"   
xpacman
(开发版本:)可以很好地实现这一点。特别是
p_funs
功能

语法是:

p_funs(caTools)  # exported
p_funs(caTools, TRUE)  # includes non-exported

如果您想要所有导出的函数(即通过
::
访问的函数),那么
getNamespaceExports(pkgName)
就可以了

如果希望包中的所有函数,包括通过
访问的函数,可以执行
ls(getNamespace(pkgName))

例如,对于
stringr
包:

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" 

因此,我们看到
ls(getNamespace(“stringr”)
除了
::
函数之外,还包含所有
getNamespace导出(“stringr”)

另一种方法是使用
collidr

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


您可能有一些以wit开头的函数名,因此ls(xxxx,all=TRUE)保证列出所有导出的函数。您还可以检查未导出的函数的源代码,即并非真正用于最终用户但在包内部使用的函数(但有时仍然有用,并且被其他人使用)。只是一个注释:在您可以列出其对象或功能之前,应该先附加该软件包。我喜欢这个答案,因为它不需要安装额外的软件包。只有基地的东西。酷!