Command for “Set working directory to source file location”

风流意气都作罢 提交于 2019-12-01 15:21:27
Romain

You can use :

source("script.R", chdir = TRUE)

and change "script.R" by the name of the file you're interested in.

Ciro
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.

This will work on most systems, it gets a little buggy with Macs.

dir <- dirname(parent.frame(2)$ofile)
setwd(dir)

Slight variation on @Ciro's answer above, for Mac users:

pathwd<-sub("/dummy.R","",system("find . -type f -name dummy.R",intern=T)[1]) 
setwd(pathwd)

Replace dummy.R with your filename of course.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!