title: Passing multiple column names of a data frame in a R function
body: <p>I have a data frame with 70+ columns. I need to perform some repetitive computations with a number of columns using each column separately.</p>
  
  <p>Based on @Ananda's approach and feedback, here is the reworded simplistic example and solution. I am still keeping the old thread at the end for the sake of discussion thread,</p>
  
  <p>Problem: Calculate sum of various columns of a data frame using a function where column names are specified as multiple arguments:</p>
  
  <pre><code>&gt; df = data.frame(aa=1:10, bb=101:110, cc=201:210, dd=301:310)
  
  &gt; myFunc(df, aa, bb, cc)
  aa series sum is 55 
  bb series sum is 1055 
  cc series sum is 2055 
  
  &gt; myFunc(df, aa, dd)
  aa series sum is 55 
  dd series sum is 3055 
  
  &gt; myFunc(df, dd)
  dd series sum is 3055 
  &gt; 
  </code></pre>
  
  <p>And myFunc function definition to accomplish this is below</p>
  
  <pre><code>myFunc = function(data, ...){
    argList = match.call(expand.dots=FALSE)$...
  
    for(i in 1:length(argList)){
      colName = argList[[i]]
      series_colName = eval(substitute(colName), envir=data, enclos=parent.frame())
      cat(colName, "series sum is", sum(series_colName), "\n")
    }
  }
  </code></pre>
  
  <p>This gives me a starting point to work with. If there is a better way to define myFunc, please let me know.</p>
  
  <p>Thanks for all the help</p>
  
  <p>::::Old Discussion Thread:</p>
  
  <p>I am still figuring my ways in R, hence bear with me please. The following sample code simulates my first try and it bombed on me. Where am I going wrong and what will be the R-ish way to do this type of computation. Please help</p>
  
  <pre><code>myFunc = function(data, y, ...){
    argList = list(...)
    argList
    #for each arg in argList
      #do some processing with data, y and column arg
  }
  
  df = data.frame(aa=1:10, bb=101:110, cc=201:210, dd=301:310)
  myFunc(df, aa, bb)
  myFunc(df, aa, bb, cc)
  </code></pre>
  
  <p>And the error message is</p>
  
  <pre><code>Error in myFunc(df, aa, bb) : object 'bb' not found
  
  Error in myFunc(df, aa, bb, cc) : object 'bb' not found
  </code></pre>
  
  <p>Adding further so that it becomes more clear.</p>
  
  <pre><code>myFunc(df, aa, c(2,4, 6))
  </code></pre>
  
  <p>works fine.</p>
  
  <p>I intend to use eval, substitute and envir in further processing to extract the values of various columns, hence I would like to pass the column names in a natural way rather than as character strings. I hope that I am able to communicate my intention clearly.</p>