2013-12-12 10 views
9

パッケージに関連付けられているすべての関数を見つける最良の方法は何ですか?私は現在、caToolsパッケージを使っています。 ?caToolsまたは??caToolsを実行した場合、単にパッケージ内の関数ではなく関数という名前の関数を検索します。 R guiのすべての機能に簡単にアクセスできますか?関数を検索する良い方法はありますか?パッケージ内の関数を検索する

答えて

8

私はあなただけを探していることを推測していますhelp(package = caTools)を入力すると、ブラウザーが開き、関連するヘルプページが表示され、「caTools」パッケージのすべての機能が一覧表示されます。

また、試してみることもできます:library(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" 
10

あなたはとあなたのパッケージ内のすべてのオブジェクトを取得することができます:あなたがして、あなたのパッケージ内のすべての関数のシグネチャを取得することができます

ls("package:caTools") 

lsf.str("package:caTools") 
+0

いくつかの関数名があります。 、ls(xxxx、all = TRUE)は、エクスポートされたすべての関数がリストされていることを保証します。また、エクスポートされていない、すなわちエンドユーザ向けのものではなく、パッケージ内部で使用されている(しかし、他の人によってはまだ有用であり、使用されている)関数のソースコードを調べることができます。 – lebatsnok

3

あなたがパッケージで動作するように設計GitHubのパッケージをダウンロードするために喜んでいる場合は、pacmanパッケージはこれに対してうまく機能します。具体的には、p_funs機能です。ここで

はレポです:

https://github.com/trinker/pacman

構文は次のとおりです。

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

超便利です、ありがとうございます! –

1

あなたはすべてのエクスポート機能(::を介してアクセスすなわち機能)をしたい場合は、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" 

しかし、我々はstringr:::is.perlがパッケージに存在することを知っている、とあなたが見ることができるよう:

だから、
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" 

を、私たちはそのls(getNamespace("stringr"))を見ます:::機能に加えて、getNamespaceExports("stringr")のすべてを含みます。

関連する問題