I have a R script that should change the working directory using setwd().
My code:
setwd(file.path(work_dir, database_dir, study))
I can pause my script just before this line is supposed to execute (using browser()) enter the code into the console without issue, but whenever the line is executed from the script I get the error box stating that there is an "error while opening file: The system cannot find the file specified." Within my script before calling the setwd, I confirmed that the path exists using file.exists(file.path(work_dir, database_dir,study)). I also restarted R studio and closed and reopened all of my scripts to make sure that was not causing the problem.
Does anyone have any other suggestions for me to try?
cannot change working directory, notcannot find, suggesting that perhaps that line is not the line that is erring. (BTW, I usefile.pathall the time to create directory paths, I think the function name could instead be file/dir-agnostic such asmake.pathorcreate.pathor similar ... but it's fine. You might instead usedir.existsinstead offile.exists, it is both logically more consistent with your intent and will err if it is indeed a file when it should be a directory.)