R:区分辅助函数与CRAN包中的main函数

时间:2014-04-21 18:14:54

标签: r cran

如何在包含大量功能的包中区分辅助功能和主功能?有没有办法通过某些标准标识符将它们分开,可以在R?

中实现

例如,我在R会话中使用sets包,如下所示。我如何从下面给出的列表中的主要功能中分离辅助功能。我可以通过阅读文档来做到这一点(有时它会明确记录一个函数作为辅助函数),但是在R中是否实现了标准标识符,说函数是辅助函数还是主函数?

library(sets)

ls("package:sets")
[1] "%..%"                              "%<%"                               "%<=%"                             
[4] "%>%"                               "%D%"                               "%e%"                              
[7] "%is%"                              "as.cset"                           "as.gset"                          
[10] "as.interval"                       "as.set"                            "as.tuple"                         
[13] "binary_closure"                    "binary_reduction"                    "canonicalize_set_and_mapping"     
[16] "charfun_generator"                 "closure"                           "cset"                             
[19] "cset_bound"                        "cset_cardinality"                  "cset_cartesian"                   
[22] "cset_charfun"                      "cset_combn"                        "cset_complement"                  
[25] "cset_concentrate"                  "cset_contains_element"             "cset_core"                        
[28] "cset_defuzzify"                    "cset_difference"                   "cset_dilate"                      
[31] "cset_dissimilarity"                "cset_has_missings"                 "cset_height"                      
[34] "cset_intersection"                 "cset_is_crisp"                     "cset_is_empty"                    
[37] "cset_is_equal"                     "cset_is_fuzzy_multiset"            "cset_is_fuzzy_set"                
[40] "cset_is_multiset"                  "cset_is_proper_subset"             "cset_is_set"                      
[43] "cset_is_set_or_fuzzy_set"          "cset_is_set_or_multiset"           "cset_is_subset"                   
[46] "cset_matchfun"                     "cset_matchfun<-"                   "cset_mean"                        
[49] "cset_memberships"                  "cset_normalize"                    "cset_orderfun"                    
[52] "cset_orderfun<-"                   "cset_outer"                        "cset_peak"                        
[55] "cset_power"                        "cset_product"                      "cset_similarity"                  
[58] "cset_sum"                          "cset_support"                      "cset_symdiff"                     
[61] "cset_transform_memberships"        "cset_union"                        "cset_universe"                    
[64] "e"                                 "fuzzy_bell"                        "fuzzy_bell_gset"                  
[67] "fuzzy_cone"                        "fuzzy_cone_gset"                   "fuzzy_inference"                  
[70] "fuzzy_logic"                       "fuzzy_normal"                      "fuzzy_normal_gset"                
[73] "fuzzy_partition"                   "fuzzy_pi3"                         "fuzzy_pi3_gset"                   
[76] "fuzzy_pi4"                         "fuzzy_pi4_gset"                    "fuzzy_rule"                       
[79] "fuzzy_sigmoid"                     "fuzzy_sigmoid_gset"                "fuzzy_system"                     
[82] "fuzzy_trapezoid"                   "fuzzy_trapezoid_gset"              "fuzzy_triangular"                 
[85] "fuzzy_triangular_gset"             "fuzzy_tuple"                       "fuzzy_two_normals"                
[88] "fuzzy_two_normals_gset"            "fuzzy_variable"                    "gset"                             
[91] "gset_bound"                        "gset_cardinality"                  "gset_cartesian"                   
[94] "gset_charfun"                      "gset_combn"                        "gset_complement"                  
[97] "gset_concentrate"                  "gset_contains_element"             "gset_core"                        
[100] "gset_defuzzify"                    "gset_difference"                   "gset_dilate"                      
[103] "gset_dissimilarity"                "gset_has_missings"                 "gset_height"                      
[106] "gset_intersection"                 "gset_is_crisp"                     "gset_is_empty"                    
[109] "gset_is_equal"                     "gset_is_fuzzy_multiset"            "gset_is_fuzzy_set"                
[112] "gset_is_multiset"                  "gset_is_proper_subset"             "gset_is_set"                      
[115] "gset_is_set_or_fuzzy_set"          "gset_is_set_or_multiset"           "gset_is_subset"                   
[118] "gset_mean"                         "gset_memberships"                  "gset_normalize"                   
[121] "gset_outer"                        "gset_peak"                         "gset_power"                       
[124] "gset_product"                      "gset_similarity"                   "gset_sum"                         
[127] "gset_support"                      "gset_symdiff"                      "gset_transform_memberships"       
[130] "gset_union"                        "gset_universe"                     "integers"                         
[133] "integers2reals"                    "interval"                          "interval_complement"              
[136] "interval_contains_element"         "interval_difference"               "interval_division"                
[139] "interval_domain"                   "interval_intersection"             "interval_is_bounded"              
[142] "interval_is_closed"                "interval_is_countable"             "interval_is_degenerate"           
[145] "interval_is_empty"                 "interval_is_equal"                 "interval_is_finite"               
[148] "interval_is_greater_than"          "interval_is_greater_than_or_equal" "interval_is_half_bounded"         
[151] "interval_is_left_bounded"          "interval_is_left_closed"           "interval_is_left_open"            
[154] "interval_is_left_unbounded"        "interval_is_less_than"             "interval_is_less_than_or_equal"   
[157] "interval_is_proper"                "interval_is_proper_subinterval"    "interval_is_right_bounded"        
[160] "interval_is_right_closed"          "interval_is_right_open"            "interval_is_right_unbounded"      
[163] "interval_is_subinterval"           "interval_is_unbounded"             "interval_is_uncountable"          
[166] "interval_measure"                  "interval_power"                    "interval_product"                 
[169] "interval_sum"                      "interval_symdiff"                  "interval_union"                   
[172] "is.charfun_generator"              "is.cset"                           "is.gset"                          
[175] "is.interval"                       "is.set"                            "is.tuple"                         
[178] "is_element"                        "LABEL"                             "LABELS"                           
[181] "make_set_with_order"               "matchfun"                          "naturals"                         
[184] "naturals0"                         "pair"                              "reals"                            
[187] "reals2integers"                    "reduction"                         "set"                              
[190] "set_cardinality"                   "set_cartesian"                     "set_combn"                        
[193] "set_complement"                    "set_contains_element"              "set_dissimilarity"                
[196] "set_intersection"                  "set_is_empty"                      "set_is_equal"                     
[199] "set_is_proper_subset"              "set_is_subset"                     "set_outer"                        
[202] "set_power"                         "set_similarity"                    "set_symdiff"                      
[205] "set_union"                         "sets_options"                      "singleton"                        
[208] "triple"                            "tuple"                             "tuple_is_ntuple"                  
[211] "tuple_is_pair"                     "tuple_is_singleton"                "tuple_is_triple"                  
[214] "tuple_outer"  

2 个答案:

答案 0 :(得分:1)

通常&#34;帮助&#34;函数(定义为:主函数使用的函数,通常不直接由最终用户使用)不会导出,除非您使用package_name:::helper_function_name语法,否则不可见。如果某个功能可见并记录在案,则通常是一个主要功能。因此,如果您想查看主要功能,请使用ls

ls("package:sets")

如果你想要所有的功能(主+助手):

ls(getNamespace("sets"))

最后,要获得辅助函数,请使用setdiff

setdiff(ls(getNamespace("sets")), ls("package:sets"))

请参阅 SO Q/A for some discussion

一个潜在的歧义是有时S3方法没有明确导出,即使它们打算用作&#34; main&#34;功能

答案 1 :(得分:0)

R库的NAMESPACE文件应该包含一个公开的导出函数列表。因此,暴露(因此公开)和非暴露(因此内部/私人)功能有很好的定义。没有关于&#39; main&#39;的正式定义。和&#39;帮手&#39;功能。你可能只会争论主要的&#39;功能应该暴露,但我不认为它是明确的。

懒惰的开发者有时包括 exportPattern("^[[:alpha:]]+") 在NAMESPACE文件中,从而暴露所有功能。在这种情况下,我可能会怀疑该库的公开函数都与main / helper函数混合在一起。但是,当我选中sets的{​​{1}}文件时,它的组织得非常好。因此,我相信NAMESPACE的公开功能得到很好的维护和必要。