【发布时间】:2015-06-23 04:34:41
【问题描述】:
在 bash 中我可以做到:
BLA=some/directory 然后
MyFavoriteFile1=/some/path/to/$BLA/myfile1.someextension
MyFavoriteFile2=/some/path/to/$BLA/myfile2.someextension
我想知道 R 中是否存在相同的情况?这样我只需在整个脚本中更改一次BLA。
【问题讨论】:
在 bash 中我可以做到:
BLA=some/directory 然后
MyFavoriteFile1=/some/path/to/$BLA/myfile1.someextension
MyFavoriteFile2=/some/path/to/$BLA/myfile2.someextension
我想知道 R 中是否存在相同的情况?这样我只需在整个脚本中更改一次BLA。
【问题讨论】:
使用file.path:
dir <- file.path("some", "path")
bla <- file.path("some", "directory")
files <- c("file1.R", "file2.exe")
file.path(dir, bla, files)
生产:
[1] "some/path/some/directory/file1.R" "some/path/some/directory/file2.exe"
您也可以使用paste 来一般地连接字符串,但file.path 确保为您的操作系统使用正确的目录分隔符,等等。
【讨论】: