I have a script (call it Main.R
) that has the following code to find itself when I run it:
frame_files <- lapply(sys.frames(), function(x) x$ofile)
frame_files <- Filter(Negate(is.null), frame_files)
main.dir <- dirname(dirname(frame_files[[length(frame_files)]]))
This is used to get the directory above its own directory, main.dir
, which is used to call other scripts relative to this path.
I'm interested in running this script from a command line, for example
R CMD BATCH Main.R
or
Rscript Main.R
Unfortunately, the commands above do not work when I call the script from the command line.
Is there any code I could put in Main.R
or a call option to R
or Rscript
that I can use instead?
More specifically, the solution would need to work in Windows.