gpt4 book ai didi

r - 如何在 R 的 setwd() 命令上换行?

转载 作者:行者123 更新时间:2023-12-04 10:55:02 26 4
gpt4 key购买 nike

我尝试将所有 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.")

但是,一些功能如 setwd()只是不会让我这样做。例如,运行
setwd("/folder/another folder/yet another folder/
what are you doing, hiding pr0n?/I think I've made my point/")

返回以下错误:
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

我试过在斜线字符以外的不同点上刹车线,但我无法让它工作。我能找到的唯一解决方法是运行
setwd(paste("/folder/another folder/yet another folder/",
"what are you doing, hiding pr0n?/I think I've made my point/",
sep = "")

哪个有效,但似乎只是为了尊重一些自定义规则而一团糟。

有没有更优雅的方法来实现这一目标?

最佳答案

一般来说,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")

关于r - 如何在 R 的 setwd() 命令上换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9571423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com