Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法使用setwd()不同级别的R函数返回目录?
setwd()
例如
> getwd() /home/folder1/folder2/
我想在不打字的情况下一口气到家setwd("../..")。写n次“../”很繁琐
setwd("../..")
一种方法是"../.."动态创建路径。
"../.."
setwd_n_levels <- function(n) { setwd(paste0(rep('..', n), collapse = '/')) } setwd_n_levels(2) getwd()
我们可以用strrep
strrep
setwd_n_levels <- function(n) { setwd(trimws(strrep('../', n), whitespace = '/')) }