获取R脚本所在路径

方法一、使用this.path包

library(this.path)
print(this.path::this.dir())

方法二、commandArgs

initial.options <- commandArgs(trailingOnly = FALSE)
file.arg.name <- "--file="
script.name <- sub(file.arg.name, "", initial.options[grep(file.arg.name, initial.options)])
print(script.name)
script.basename <- dirname(script.name)
print(script.basename)

参考来自 https://www.jianshu.com/p/7786556edec3

你可能感兴趣的:(获取R脚本所在路径)