title: how to make a loop for reading several nc files as a raster and then write them as envi?
body: <p>This code given below (<a href="https://stackoverflow.com/a/13700965/1451109">developed by stackoverflow users</a>) will read a variable from a netcdf file and write it as an envi file.<br>
  This code is working fine but I have several netcdf files like this one and I want to make a loop to do this for all files in the directory.<br>
  The files are stored in a directory whose path is </p>
  
  <pre><code>d &lt;-  flip(t(d), direction = "x") 
  rf &lt;- writeRaster(d, filename="last.envi", overwrite=TRUE)
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>for(i in 1:length(a)){
      d &lt;- raster(a[i], varname = "soil_moisture_c")
      rf &lt;- writeRaster(d[[i]], filename="%d.envi", overwrite=TRUE)
      }
  </code></pre>
  
  <p>but got this error</p>
  
  <pre><code>Error in function (classes, fdef, mtable) : 
  unable to find an inherited method for function ‘writeRaster’ for signature ‘"numeric", "character"’
  </code></pre>