确定执行脚本的路径 [英] Determine path of the executing script
本文介绍了确定执行脚本的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为foo.R
的脚本,其中包括位于同一目录中的另一个脚本other.R
:
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")
但是我希望R
能够找到other.R
,而不管当前的工作目录是什么.
But I want R
to find that other.R
no matter what the current working directory.
换句话说,foo.R
需要知道它自己的路径.我该怎么办?
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.
这篇关于确定执行脚本的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文