How to set the current file location as the default working directory in R programming?

后端 未结 5 1092
执笔经年
执笔经年 2020-12-30 01:11

I want to make the current file location as the working directory.

Using Rstudio (Works!):

# Author  : Bhishan Poudel
# Program :         


        
5条回答
  •  时光取名叫无心
    2020-12-30 01:25

    Try using parent.frame(3) in you function:

    setwd_thisdir <- function () {
      this.dir <- dirname(parent.frame(3)$ofile)
      setwd(this.dir)
    }
    

    See ?parent.frame or http://adv-r.had.co.nz/Environments.html#calling-environments.

    You may also look at the chdir option of the source function (?source).

提交回复
热议问题