I use the package dplyrin R. Using this, I want to create a function like
require(dplyr)
aFunction <- function(x, optionalParam1="abc"){
cat(optionalParam1, "\n")
return(x)
}
myFun <- function(data, ...){
result <- data %>% mutate_each(funs(aFunction(., ...)))
}
and then name it like
data = data.frame(c1=c(1,2,3), c2=c(1,2,3))
myFun(data)
myFun(data, optionalParam1="xyz")
when called, myFunall optional parameters must be passed to aFunction. But instead, an error occurs '...' used in an incorrect context.
This is the same function without dplyr, which works the way it should work ...
myFun2 <- function(data, ...){
for(c in colnames(data)){
data[,c] = aFunction(data[,c], ...)
}
}
how can i achieve the same result with dplyr?
Jonas source
share