I work in a school district and plan to produce unique PDF reports that I will send to a shared drive containing a folder for each of the 40+ schools in my district.
I am trying to set the working directory within my for loop so that each school will get a report tailored for their school. The schools files are named based on the levels of some variable named “school_name” and now I want to write to those folders based upon the fact that I am using data for school[i].
schools <- levels(as.factor(data$school_name))
for (i in 1:length(schools)) {
setwd("W:\\Data Analysis Results\\"paste(schools[[i]]))
## some command to create a unique PDF report for school [[i]]
}
This minor change should do it:
The file.path function is made for these tasks.