I understand that in R to set my working directory I can do:
setwd("~/dir1/dir2/mydir")
If mydir is a unique directory name, is there way to specify the working directory without stating dir1/dir2 ?
Thanks
Sys.glob
does what you want:
setwd(Sys.glob("~/*/*/mydir"))
If you don't know how deep it's nested, you can use list.files
or dir
:
list.files(path="~", pattern="mydir", all.files=TRUE, full.names=TRUE,
recursive=TRUE, ignore.case=FALSE, include.dirs=TRUE)
来源:https://stackoverflow.com/questions/12324539/specify-directory-with-setwd