title: using path in a function in R
body: <p>Have this. Seems simple but throws an error when asking for a result.</p>
  
  <pre><code>directory &lt;- setwd("C:/Users/Spin/Documents/R/pollutant/specdata")
  pollutantmean &lt;- function(directory, pollutant, id = 1:332){
  file.list &lt;- list.files(path = directory, pattern = ".csv", full.names = TRUE)
  cum_vector = numeric()
  
   for(i in id){
     data &lt;- read.csv(file.list(i))
     cum_vector &lt; - c(cum_vector, data[[pollutant]])
   }
  
   mean(cum_vector, na.rm = TRUE)
  }
  
  pollutantmean(1:10)
  </code></pre>
  
  <blockquote>
    <p>Error in list.files(path = directory, pattern = ".csv", full.names =
    TRUE) :    invalid 'path' argument</p>
  </blockquote>
  
  <p>used <code>file.path</code> as well</p>