1

I am trying to use function A within function B. I want to fix the attributes of function A dependent on the input from function B. As a simple example:

somfun<-function(x,atra){

   functionA(x,atra$subset)

}

Sorry if it is vague. But I need atra to operate as the arguments like paste(x,sep='sss') etc. but with an arbitrary number of arguments. `atra would be a named vector for example or whatever was appropriate.

example

atra<-list(a=1:2,b=3:4,c=5:6,1:2,sep='')

x<-'data'
somfun<-function(x,atra){

   c(atra[[1]],atra[[2]],atra[[3]],paste(x,atra[[5]]))

}

but i want all the names to preserve and paste to realise that atra[[5]] is saying sep=''

user1609452
  • 4,366
  • 1
  • 12
  • 20

1 Answers1

2

You want the do.call function, which can call a function using a list (including named arguments). For example:

do.call(paste, list("hello", "world", sep="/"))
# [1] "hello/world"
David Robinson
  • 74,512
  • 15
  • 159
  • 179