title: Error in file(file, "rt") : cannot open the connection
body: <p>I'm new to R,  and after researching this error extensively, I'm still not able to find a solution for it. Here's the code. I've checked my working directory, and made sure the files are in the right directory. Appreciate it. Thanks</p>
  
  <pre><code>pollutantmean &lt;- function(directory, pollutant = "nitrate", id= 1:332)            
  {                 if(grep("specdata",directory) ==1) 
              {
                      directory &lt;- ("./specdata")
              }
              mean_polldata &lt;- c()
              specdatafiles &lt;- as.character(list.files(directory))
              specdatapaths &lt;- paste(directory, specdatafiles, sep="")
                              for(i in id) 
                      {
                      curr_file &lt;- read.csv(specdatapaths[i], header=T, sep=",")
                      head(curr_file)
                      pollutant
                      remove_na &lt;- curr_file[!is.na(curr_file[, pollutant]), pollutant]
                      mean_polldata &lt;- c(mean_polldata, remove_na)
                      }
              {
                      mean_results &lt;- mean(mean_polldata)
                      return(round(mean_results, 3))
              }
  } 
  </code></pre>
  
  <p>The error I'm getting is below:</p>
  
  <pre><code>Error in file(file, "rt") : cannot open the connection
  
  file(file, "rt")
  
  read.table(file = file, header = header, sep = sep, quote = quote, 
      dec = dec, fill = fill, comment.char = comment.char, ...)
  
  read.csv(specdatapaths[i], header = T, sep = ",")
  
  pollutantmean3("specdata", "sulfate", 1:10)
  
  In addition: Warning message:
  In file(file, "rt") :
    cannot open file './specdata001.csv': No such file or directory
  </code></pre>