对于工作目录设置为源文件的位置R指令 [英] R command for setting working directory to source file location

查看:406
本文介绍了对于工作目录设置为源文件的位置R指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作出R.一些教程各R code被包含在一个特定的文件夹。有在那里的数据文件和其他文件。我想打开 .R 文件和源是这样的,我没有改变Rstudio工作目录,如下所示:

I am working out some tutorials in R. Each R code is contained in a specific folder. There are data files and other files in there. I want to open the .r file and source it such that I do not have to change the working directory in Rstudio as shown below:

有没有R中自动指定我的工作目录的方式。

Is there a way to specify my working directory automatically in R.

推荐答案

我知道这个问题已经过时,但是我正在寻找的一个解决方案,以及和谷歌在列出了顶部:

I know this question is outdated, but I was searching for a solution for that as well and Google lists this at the very top:

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

把某处到文件(最好是开始时,虽然),从而使WD变为根据该文件

put that somewhere into the file (best would be the beginning, though), so that the wd is changed according to that file.

又见得到`source`d文件

这篇关于对于工作目录设置为源文件的位置R指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆