当我尝试设置工作目录时收到"无法更改工作目录"错误:
setwd("C:UsersalimoDesktopDataVisualizationwithggplot2.R")
*Error: 'U' used without hex digits in character string starting ""C:U"*
然后我跑了:
options(PACKAGE_MAINFOLDER="C:/Users/...")
并将所有"替换为"/",但这次我得到了这个错误:
cannot change working directory
是的,编写文件或目录的路径有时会有点痛苦,尤其是当您跨不同平台移动时!
setwd()
设置工作目录,因此这意味着您需要指定目录,而不是文件。
每当我不确定单/双(反(斜杠时,我喜欢使用基数 R 中的file.path()
,它以独立于平台的方式添加正确的分隔符:
file.path("~", "myfolder", "myfile.R")
因此,对于您的情况:
setwd(file.path("C:", "Users", "alimo", "Desktop"))