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',我们必须添加许多'\',有时很无聊有没有更简单的方法?(就像 Python 可以添加 'r' )
setwd('C:\Users\Administrator\Desktop\myfolder') # can't work setwd('C:\\Users\\Administrator\\Desktop\\myfolder') # can work,but havt to add many '\'
您可以使用r(对于原始字符串)并添加括号:
r
> r"(C:\Users\Administrator\Desktop\myfolder)" [1] "C:\\Users\\Administrator\\Desktop\\myfolder" >
现在:
setwd(r"(C:\Users\Administrator\Desktop\myfolder)")
或从剪贴板读取自动添加额外的斜杠:
setwd(readClipboard())