library("rstudioapi")
stewed(dirname(getActiveDocumentContext()$path))
#载入包
library("rstudioapi")
#获取当前文件的路径
getActiveDocumentContext()$path
#获得文件所在文件夹的路径
dirname(getActiveDocumentContext()$path))
#dirname returns the part of the path up to but excluding the last path separator, or "." if there is no path separator.
参考 ☕R语言tip | 方便快捷的获取目标文件路径: rstudioapi与here包的应用小结 - 知乎