Perlnika
Perlnika

Reputation: 5056

pass arguments to the R function from a variable

I have a R function with following header:

getFileNames <- function(sex=NULL,species=NULL,name=NULL){

When I call it like this, all is fine:

getFileNames(sex="F",species="Pan paniscus")

However, I would like to call it with variable filters like this:

getFileNames(filters)

Now I am trying to figure out how to define filters. I have tried

filters<-paste("sex=F","species=Pan paniscus",sep=",")

with no success.

Upvotes: 0

Views: 37

Answers (1)

user31264
user31264

Reputation: 6727

The best you can do is to use do.call :

filters = list(sex="F",species="Pan paniscus")
do.call(getFileNames, filters)

Upvotes: 1

Related Questions