In R, I'm working on "./parent/Child/A". I want to move back parent folder "child", but when I type full path. It lost many times.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
setwd('..')
will move up one directory without entering the absolute path. Here's an example
> getwd()
[1] "C:/Users/D/Desktop/EDABaseball"
> setwd('..')
> getwd()
[1] "C:/Users/D/Desktop"
回答2:
I think you want to move back to the working directory ./parent/Child/
. This can be done in 2 ways, assuming your current working directory is ./parent/Child/A
1) setwd("..")
2) setwd("./..")
3) setwd("./parent/Child")
回答3:
Moves up one directory in Linux
setwd("../")
回答4:
I also find dirname()
function pretty useful especially if your path is saved in a variable:
mypath <- getwd()
# The path of the parent directory:
dirname(mypath)