I have a script called foo.R
that includes another script other.R
, which is in the same directory:
#!/usr/bin/env Rscript
message("Hello")
source("other.R")
But I want R
to find that other.R
no matter what the current working directory.
In other words, foo.R
needs to know its own path. How can I do that?
Here there is a simple solution for the problem. This command:
script.dir <- dirname(sys.frame(1)$ofile)
returns the path of the current script file. It works after the script was saved.