特定の引数が存在しないか存在するかを処理できるように、ラッパー関数に柔軟性を組み込むにはどうすればよいですか。
より具体的には、FD パッケージの gowdis 関数のラッパーを構築しており、引数「asym.bin」および「ord」を含めるか除外するかをユーザーに選択させたいと考えています。以下の例に与えられたアドバイス:
library(FD)
?gowdis
x<-data.frame("Trait1" =c(1,1,0),
"Trait2"=c(1,1,1),
"Trait3" =c(1,1,0),
"Trait4" =c(0,0,1))
rownames(x)<-c("A","B","C")
w<-c(0.25,0.25,0.25,0.25)
m<-2
asym.bin<-c(1,4)
wrapper.function = function(x,w,m) {
gdis<-gowdis(x,w)
gdis2<-gdis*m
gdis2
}
#excluding the ord and asym.bin works fine
wrapper.function(x,w,m)
A B
B 0.5
C 1.0 1.5
#but I want to give the user the option of including these wrapped arguments i.e.
wrapper.function = function(x,w,m,asym.bin,ord) {
gdis<-gowdis(x,w,asym.bin,ord)
gdis2<-gdis*m
gdis2
}
wrapper.function(x,w,m)
ただし、これはエラーメッセージを返します
「match.arg(ord) のエラー: 引数 "ord" がありません。デフォルトはありません」