get filename and path of `source`d file

前端 未结 6 1754
心在旅途
心在旅途 2020-12-08 08:20

How can a sourced or Sweaved file find out its own path?

Background:

I work a lot with .R scripts or .Rnw files. My projects are o

6条回答
  •  [愿得一人]
    2020-12-08 09:08

    I have no direct solution how to obtain the directory of the file itself but if you have a limited range of directories and directory structures you can probably use

     if(file.exists("c:/somedir")==TRUE){setwd("c:/somedir")}
    

    You could check out the pattern of the directory in question and then set the dir. Does this help you?

提交回复
热议问题