I had a function with a signature like this:
myFunction=function(class="Class",v1='y',v2='y',dfparam=df){
where df
is a dataframe and it is assumed that there is an attribute called Class
in df. I wanted to make it more general so that it can accept a variety of dataframes, df, not just one that has an attribute called Class.
So I added in a className
parameter and classValue
parameter to replace the class parameter. Also, I want to allow unlimited arguments v1, v2, v3 etc. and so I am using the elipsis like this:
myFunctionGeneral = function(className="Class", classValue="democrat", dfparam=df, ...){
arguments <- list(...)
Prior to using the elipsis, I had a line that used the arguments as follows:
X_bool=dfparam$V1==v1 & dfparam$V2==v2
I started out doing this:
X_bool=dfparam[,2]==arguments[1] & dfparam[,3]==arguments[2]
but I want to do this for an unlimited number of possible paremeters in the elipsis. So I need to expand this statement by somehow unraveling the ellipsis. Here is an example:
install.packages("vcd")
library(vcd)
data(Arthritis)
AAr=Arthritis[,-c(1,4)]
myFunctionGeneral=function(className="Class",classValue="democrat",dfparam=df, ...){
dfparam$names<-rownames(dfparam)
arguments<-list(...)
dfparamDroppedClass=dfparam[,-1]
#X_bool=dfparam[,2]==arguments[1] & dfparam[,3]==arguments[2]
X_bool=do.call(all, Map("==", dfparamDroppedClass, arguments))
X=dfparam[X_bool,]
}