title: How to write a function for a variable name?
body: <p>I have an object that is <code>st</code></p>
  
  <pre><code>str(st)
  List of 34
  $ cell_ele    : num [1:2000, 1:1000] 999 999 ...
  </code></pre>
  
  <p>Now I want to write  a function</p>
  
  <pre><code>myfun &lt;- function(var){
  rt= st$var 
  rt=raster(rt)
  out &lt;- writeRaster(rt, filename = "C:\\var_data")
                        }
  </code></pre>
  
  <p><code>var</code> will be used twice , to be read and then to be part of the output file name</p>
  
  <pre><code> myfun (cell_ele)
   Error in raster(matrix(data = rt)) : 
   error in evaluating the argument 'x' in selecting a method for function 
  'data' must be of a vector type, was 'NULL'
  </code></pre>
  
  <p>I tried it without the function and it worked fine. The problem is in the function</p>