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 pollutantmean <- function(directory, pollutant = "nitrate", id= 1:332) { if(grep("specdata",directory) ==1) { directory <- ("./specdata") } mean_polldata <- c() specdatafiles <- as.character(list.files(directory)) specdatapaths <- paste(directory, specdatafiles, sep="") for(i in id) { curr_file <- read.csv(specdatapaths[i], header=T, sep=",") head(curr_file)