Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

source() path relative to the current script directory?

Tags:

r

In my main R script, I am doing source("some/path/script1.R"). This script includes another script in that directory:

source("script2.R")
...

Now, this will not work. The simplest solution is to use source("some/path/script2.R") in script1.R. But that's ugly, and not robust at all - it can break if directories some/path change. I want reasonable solution where script1.R includes script2.R irrespective of how some/path looks like.

Is there a reasonably simple way to specify source() path relative to the current script?

like image 656
Tomas Avatar asked Oct 17 '25 14:10

Tomas


1 Answers

You can use :

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

like image 138
Clemsang Avatar answered Oct 19 '25 05:10

Clemsang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!