RStudio has a useful feature:
Session -> Set Working Directory -> To Source File Location
Is there a way to do this without using the
pathwd<-sub("/filename","",system("find -perm -g=w -type f -name 'filename'",intern=T)[1]) setwd(pathwd)
Make sure your file's name is unique.