我尝试将所有R脚本行保持在80个字符以下.无论何时涉及到字符串,这都可能是一个挑战,但通常只是在不使用任何特殊字符的情况下打破行,如下所示:
plot(x, y, main = "some reeeealy long title, so long that
I need to break it into several lines
in order to satisfy my ****-retentive
self.")
Run Code Online (Sandbox Code Playgroud)
但是,有些功能setwd()只是不让我这样做.例如,跑步
setwd("/folder/another folder/yet another folder/
what are you doing, hiding pr0n?/I think I've made my point/")
Run Code Online (Sandbox Code Playgroud)
返回以下错误:
Error in setwd("/folder/another folder/yet another folder/\n
what are you doing, hiding pr0n?/I think I've made my point/") :
cannot change working directory
Run Code Online (Sandbox Code Playgroud)
我试过在斜线角色以外的不同点上制动线,但是我无法让它起作用.我能找到的唯一解决方法是运行
setwd(paste("/folder/another folder/yet another folder/",
"what are you doing, hiding pr0n?/I think I've made my point/",
sep = "")
Run Code Online (Sandbox Code Playgroud)
哪个有效,但为了尊重一些自定义的规则,似乎很多混乱.
是否有更优雅的方式来实现这一目标?
一般来说,这paste是我能想到的唯一方法,但是,在这种特殊情况下,它file.path是一个更好的选择,而不是paste自动为您的平台提供正确的分离字符.
file.path("/folder", "another folder", "yet another folder",
"what are you doing, hiding pr0n?",
"I think I've made my point")
Run Code Online (Sandbox Code Playgroud)