process.files <- function(fn) { ## read in *_tracks.csv file in.data <- read.csv(fn) ## apply functions and call in weather data tmp <- correct.tracks(add.weather(track.sum(in.data), weather.df)) ## create new file name: *_stats.csv f.n <- sub("_tracks.csv", "_stats.csv", fn) ## write data to a *_stats.csv file write.csv(tmp, paste(f.n), row.names = FALSE) }