I want to be able to change the directory I am working in whilst using the R command line interface. I do not want to change the working directory but only change the directory temporarily in much the same way one changes directories by using "cd".
Can this be done and if so how do I do this?
setwd('path')
Just stick the path in and you're done.
R setwd is equivalent to the shell cd. If you have 3 subdirectories (dirA, dirB, and dirC) and you want to do some work inside the directory you need to write the following code:
dirs=c("dirA", "dirB", "dirC") # normally you get these by some means
# not through hard-coding; here is for example only
pwd <- getwd()
for (d in dirs) {
setwd(d)
# do some work in the subdirectory
setwd(pwd) # return to parent directory
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With