[R] Source inside source

Benilton Carvalho bcarvalh at jhsph.edu
Tue Jul 17 00:19:29 CEST 2007


the smarter thing is to write a package, so you don't need source()  
at all.

but your problem will be fixed if you use the full path instead:

source("/home/user/dir1/dir2/file2.R")

(and obviously you could pass the path as an argument to whatever  
function you're using...)

b

On Jul 16, 2007, at 6:11 PM, Alberto Monteiro wrote:

> Is there a way to know where is the source, so as to make a source  
> call
> inside another source smarter?
>
> As an example:
>
> file1.R is in directory /files/dir1/
>
> file2.R is in directory /files/dir1/dir2/
>
> In file1.R, there is this line:
>
> source("dir2/file2.R")
>
> So, if I setwd to /files/dir1/, and then I call source("file1.R"),
> it will run correctly. However, if I setwd to /files, then
> call source("dir1/file1.R"), it will give an error when
> trying to source file2.R
>
> Alberto Monteiro
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list