title: r error in rep(value, length.out = n) : attempt to replicate an object of type 'closure'
body: <p>I'm trying to write a function that can apply another function to a number of data.frames at one time. The data.frames are named DATA_1, DATA_2, etc. and the variable 'actioncol' is to indicate the column that has to be changed. This is my code so far:</p>
  
  <pre><code>gsubFUN &lt;- function(name, actioncol, ...){
    df.vec &lt;- ls(pattern =  paste("name", "*", sep="_"), envir=.GlobalEnv)
    for(ii in 1:length(df.vec)){
    DATA &lt;- get(df.vec[ii])
    DATA[,actioncol] &lt;- gsub(pattern.vec[ii], replace.vec[ii], DATA[,actioncol])
    assign(paste(name, ii, sep = "_"),DATA, envir = .GlobalEnv)    
    }
  }
  </code></pre>
  
  <p>I am aware that my code may be quite messed up, but it does work. Since I would like the outer function to apply other functions (not just gsub) on the data.frames, too, I tried to replace it with a variable:</p>
  
  <pre><code>multiDfFUN &lt;- function(name, actioncol, FUN, ...){
    df.vec &lt;- ls(pattern =  paste(name, "*", sep="_"), envir=.GlobalEnv)
    for(ii in 1:length(df.vec)){
    DATA &lt;- get(df.vec[ii])
    DATA[,actioncol] &lt;- match.fun(FUN)
    assign(paste(name, ii, sep = "_"),DATA, envir = .GlobalEnv)    
    }
  }
  
  multiDfFUN(name="audi", actioncol="color", FUN=gsub, pattern=pattern.vec[ii],
         replacement=replace.vec[ii], x=DATA[,actioncol])
  </code></pre>
  
  <p>However, this now returns an error message:</p>
  
  <pre><code>error in rep(value, length.out = n) : 
     attempt to replicate an object of type 'closure'
  </code></pre>
  
  <p>I don't even understand the meaning of this. Searching the web wouldn't help it either. Could the arguments pattern, replacement &amp; x when calling the function be the reason for this? I would be really glad if somebody could enlighten me on this issue or even point me to a simple solution (if there is any). </p>
  
  <p>Many thanks in advance.</p>